restblogging.blogg.se

Drupal paragraphs
Drupal paragraphs







Using Paragraph's API function, getParentEntity(), we can run Xdebug in the referenced paragraph bundle and evaluate the expression, $paragraph->getParentEntity(). In the case of creating a custom theme hook, we can use the Drupal 8 API's function hook_theme_suggestions_HOOK_alter where 'HOOK" is the discovered theme hook above " paragraph." In this way, we can use theme_suggestions_paragraph_alter. Inspecting the elements in Chrome, we see that our theme hook is named paragraph.įrom the above information, we can leverage template_preprocess_paragraph for further debugging using Xdebug. Now that we've added some content, we can start to debug. See the resources section below for more information. In addition, you'll want Twig debugging enabled in your local settings files. I like to use Docksal for my local setup which makes it easy to get up and running with Xdebug. Once that's all setup, add content and ensure that your local Drupal environment is setup for theming and development. The Paragraphs UI showing the relationship between the referencing and referenced paragraphs This diagram outlines our architectural modelĮssentially you would create a regular paragraph type with an image and a textarea, " Image & Text." Then, create another paragraph type, " Image & Text Reference" that points to Image & Text. The we see a visualization of "Cards" as one possible option. In this, we see that the referencing paragraph has a select list, " Choose a Style" to select how the referenced entities will appear. The diagram below outlines our design pattern. With this type of referenced entity paradigm, one can create a custom theme hook according to a setting in the referencing paragraph such as a select list with a set of "style options." In this way, we can theme with custom templates, HTML, and CSS depending on the style selection. Thus, the referencing paragraph is a container of multiple, similar sets of child entities that can be re-purposed in different manners depending on a setting in the referencing paragraph. The parent or "referencing paragraph" points to another paragraph type that contains an image, text, and title.

drupal paragraphs

The use case for this might be to build something like a grid of cards, an image gallery, or a carousel.

drupal paragraphs

For example, when using the Paragraphs module to build structured modular content, imagine that you have a paragraph type that references another paragraph type. A common architectural model in Drupal is for one entity to reference another.









Drupal paragraphs