Drupal 8 - creating an accordion field - list

In Drupal 8 -- I want to modify the basic-page content type to be able to support an "accordion field type"
I've seen the list field type - that can have unlimited fields -- but I am looking for a solution that can feature -- header/body - type features.

Drupal core sets you up well for your need--as it does several common UI requirements like accordions. You can reuse existing core assets pretty easily, and if this route meets your requirements, you'll get some admirable maintenance benefits from the fact that core gets more attention from the Drupal community than any given contrib module.
Two ways core could help:
you can invoke the jQuery UI Accordion that ships with core.
you can pattern something on the Toolbar Menu, which "Builds a nested accordion widget".
If the first option looks promising, the Examples module gives an example for how to use the core jQuery assets, specifically focusing on the accordion UI. (That's called serendipity incarnate!) Here's the javascript code:
(function ($) {
'use strict';
$(function () {
$('#accordion').accordion();
});
})(jQuery);
and here's the module code:
function js_example_theme() {
return [
'js_example_accordion' => [
'template' => 'accordion',
'variables' => ['title' => NULL],
],
];
}
Couldn't be easier. Note that if a custom module is less suited than adding the feature in your theme, you have either option available.

There is no module to handle this for you, the solution is to create unlimited Entity Reference in your content type, it must have two fields, Title and Body as you want, and to convert it to accordions you should customize new entity field theme and implement accordion there.
Another solution is, handle it by https://www.drupal.org/project/views_bootstrap which support accordion or https://www.drupal.org/project/faqfield module :
Features:
Configurable default text formats
Configurable answer widget
Types: Normal textareas, textfields and formatable textareas
Formatable textareas for any Wysiwyg editor
Configurable number of rows for textarea widget
Field formatters
jQuery Accordion UI
Simple themeable text
Definition list (HTML <dl>)
Anchor link list
Accordion display options
Choose first active question
Collapse open questions
Event to open/collapse questions (eg. mouseover, click)

Related

How to build a meta-driven application in emberJS

Note: The English used in this article (along with the terms) may be a bit "out of order" since my native language is not English. Rest assured I have tried my best to make it as readable as possible, and if I have missed anything please do comment before downvoting so I may update the question accordingly (I'm still new to this)
So I've searched most of the internet for a solution to this, to find a tutorial that would guide me on the metadata driven approach for building an application on EmberJS. The documentation on Ember doesn't explain anything about the approach, just a function definition of extractMeta here, and a basic overview of how to handle metadata here.
What I want to achieve is to build a portal, with Sugar as the back-end for the application. The application will use REST API for making calls to extract the data as well as the metadata of the application. We want to make the application generic, so that no matter what module is called, the metadata is extracted to determine the fields required in the model, a filtered portion of the data needed from the call is populated into the model accordingly and the is displayed in a generic template, that will be global and used throughout the application.
The metadata includes various items such as buttons, panels, attributes(each with multiple layers of data within) etc, each may be used once or multiple times within the call or not at all. For example, for displaying the application would require the attributes for display within the table, as well as buttons for adding, deleting updating etc. Upon click the panel may be required for say, adding a particular record, which itself may contain various fields.
As an example, is the default Sugar instance that shows the leads in the data, notice how it contains various components.
Here, another example, of the panel that appears when I click the create button in the leads list, notice the fields that appear within the panel
Please Note that I do understand how to make the REST API calls for the data as well as the metadata. But how to turn that into a generic meta driven application is what I am struggling with. Thanks in advance!
If I understand this correctly, you're looking for some kind of generic UI builder based off of returned data from a REST endpoint. Ember provides the component helper.
The {{component}} helper can be used to defer the selection of a
component to run time. The {{my-component}} syntax always renders the
same component, while using the {{component}} helper allows choosing a
component to render on the fly. This is useful in cases where you want
to interact with different external libraries depending on the data.
Using the {{component}} helper would allow you to keep different logic
well separated.
{{#each model as |post|}}
{{!-- either foo-component or bar-component --}}
{{component post.componentName post=post}}
{{/each}}
Read here for a more thorough explanation.
What you essentially need to do is build a bunch of different components for each of the possible attributes from the metadata. Your models will contain what components they should render and you'll use the component helper to dynamically render the correct elements.
If you're using a table based approach, have a look at ember light table. They leverage this approach heavily with how they build the columns for their tables and support custom components:
columns: computed(function() {
return [{
label: 'Avatar',
valuePath: 'avatar',
width: '60px',
sortable: false,
cellComponent: 'user-avatar'
}, {
label: 'First Name',
valuePath: 'firstName',
width: '150px'
}];
})
As you see here, the columns are rendered generically and they use the cellComponent property to determine which component type to render.

Sitecore 8 implement tooltip on RTE authored content

We have a requirement to implement tooltips for words that are authored in Sitecore RTE.
The idea behind is that user should be able to hover over the word and see it's description/meaning.
Is this possible to achieve in sitecore? Did a quick search on marketplace but could not find any modules.
Below are some options to consider for achieving what you described.
Inject Tooltip HTML in a renderField pipeline
In this option, you would extend the renderField pipeline. First, you will need to ensure that you are dealing with a rich-text field, and if so, locate terms and replace them with the necessary markup that is required for the tooltip. This could be as simple as wrapping the word in an <abbr> or perhaps a <span> element with a CSS class. The list of terms and tooltip content could be sourced from items in Sitecore or a custom Sitecore Dictionary. Caching the terms would be essential as this pipeline processor is invoked frequently every time a field is rendereded.
Progressive enhancement with JavaScript
This approach is almost entirely based on the client-side. Terms could be located and replaced fairly easily with the help of JQuery. If the list of terms is of a reasonable size, they could be bootstrapped into a JavaScript variable. Once terms are located and enhanced, a separate, asynchronous call to a REST endpoint could be made when hovering or clicking the term. The API would accept a term and respond with the term's definition.
HTML Snippet in RTE Editor
Sitecore RTE editor can be extended with additional buttons. One of these options allows you to insert predefined snippets of HTML. The RTE editor also has a setting to specify a CSS file to style the content within the field (<setting name="WebStylesheet" value="/css/yourstylesheet.css" />). Styling would be necessary in order to target the description markup and make it visible to be edited, whereas, on the public site, the description markup would normally be hidden by default until the term is clicked on or hovered over.
Dynamic Link Replacement
http://www.layerworks.com/blog/sitecore-token-replacement

How do I emulate RenderSection in Sitecore?

I know that sitecore mvc dos't support RenderSection.
Is it any way to emulate it with Sitecore MVC ?
I just would like to have only required scripts for specific page.
Of course I can split it to 2 files and to View Rendering but it is seems not good way.
This is not something that you may do easily. It is all about creating appropriate html helpers for that. Here is previous StackOverflow question describing how to implement that:
Using sections in Editor/Display templates
Also this article may help you as well:
http://tomkamphuis.blogspot.co.uk/2013/04/sitecore-and-mvc-rendersections.html
What I did to solve this issue was to create add the following Placeholder in my main layout page (for me, at the end of the Javascript script tags)...
#Html.Sitecore().Placeholder("javascript")
Next add a Sitecore View Rendering that contains the Javascript...
#using Sitecore.Mvc
#using Sitecore.Mvc.Presentation
#model RenderingModel
<script>
$(function () {
// your javascript
});
</script>
This rendering then gets added to the Design Layout of the content item assigning it to the placeholder "javascript".
As a beginner with Sitecore, I'd be interested what others thought of this solution.

"there are no allowed placeholders" - why can't I add forms to my presentation?

I'm running Sitecore 7.2 with Web Forms For Marketers 2.4.
I have a placeholder settings main. That placeholder has the WFFM form control listed under "allowed controls". The "restricting placeholders" app also lists the main placeholder as the only selected placeholder.
I have a layout standard that points at a .cshtml file Standard.cshtml.
I have a template standard page. On the __Standard values of that template I've defined a presentation under the "default" device: layout is standard, and the main placeholder is listed under "placeholder settings".
My understanding is that I should be able to "insert form" onto either the __Standard values or on to content item instances of the standard page template. But every time I try either of those I get "there are no allowed placeholders in order to insert a new form". What do I need to do to get WFFM to let me add a form to my items?
WFFM doesn't work with Sitecore MVC. Sad panda.
https://kb.sitecore.net/articles/522918
There are a couple of workarounds floating around (e.g. http://www.chrisvandesteeg.nl/2014/02/11/usercontrol-renderings-in-a-sitecore-mvc-website-wffm-for-mvc/), but I don't think they're supported.
It sounds like you have everything setup correctly in order to insert a form into the main placeholder (possible security issues, notwithstanding). I believe the issue is the fact that the WFFM module is strictly Web Forms only at the moment and does not work with MVC layouts and renderings. Because your layout is a .cshtml file, Sitecore will trigger the MVC pipeline.
Apparently there is an update in the works that will support MVC and possibly support for a wizard / multi-stepped feature.
In the meantime, I have had to work around the issue by creating separate ASPX layouts / templates for form landing pages like the one below. The downside here is that you have to manage separate code paths for both MVC and Web Forms.
https://www.montereybayaquarium.org/support-us/membership/become-a-member-now

Can I insert a Component TEMPLATE Link in the Tridion GUI?

In Tridion, similar to how a field in a schema or metadata schema can either be text, embedded schema, or component link... is there a way to allow the field to be an item select like a component link, but select different types of Tridion objects instead of components?
I'd like the user to be able to select a Compound Component Template or a Page object via selecting it through the interface instead of typing in the tcm into a text field and reading that value.
Is this possible?
No. Links to Component Templates are not handled by the Tridion GUIs. The Tridion Content Manager back-end can handle links to Component Templates in some situations, which is why (for example) you can see the Component Templates show up in the WhereUsed dialog of a Page.
Most people end up using a regular text field for holding such a Component Template link and then use something like Bart's Item Selector to provide an input aid.
You must be careful by creating links to other types than components because they might not be content portable and you will get issues after porting those fields from one environment to another.
Basically the tcm uris won't be resolved by content porter.
This would have to be achieved by building a custom CME (GUI) extension.