Hot answers tagged

3

The node in a field template is the parent entity you find in element['#object'], which you can use to build the path: {{ path('entity.node.canonical', {'node': element['#object'].id}) }}


2

Drupal textfield widget can only be applied to string fields. https://git.drupalcode.org/project/drupal/blob/8.7.4/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php#L9 However it's not a big deal to alter its definition and make it support long strings. /** * Implements hook_field_widget_info_alter(). */ function ...


1

Sollution: Associative array: array_push($mealsArray, ["meal" => [ 'strMeal' => $mealTitle, 'strMealThumb' => $mealImage, 'mealUrl' => $mealTitleUrl ] ]); Twig: {% for meal in meals %} {% for fields in meal %} <div class="u-col-md-3 u-col-xs-6"> <div class="m-recipe"> <a ...


1

Based on the comments to the question, I extended the EntityReferenceEntityFormatter class and modified one part in the viewElements method (the rest is the same): $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId()); $elements[$delta] = $view_builder->view($entity, $view_mode, $entity->language()->getId(...


1

Without preprocessing, directly in Twig: {# get owner entity #} {% set owner_entity = element['#object'] %} {# render id #} id = {{ element['#object'].id }} {# render raw field value #} field foo = {{ element['#object'].field_foo.0.value }}


1

You should maybe preprocess you the URL in place. Via template_preprocess_field get the node ID, build the path alias, send it to Twig. /** * Implements template_preprocess_field__FIELD_NAME(). */ function MYTHEME_preprocess_field__MYFIELD(&$variables) { if ($variables['element']['#entity_type'] === 'node') { $node = $variables['element']['#...


Only top voted, non community-wiki answers of a minimum length are eligible