New answers tagged

0

Both - node's field_collection field and field_collection's inner fields should be translatable. Otherwise you will have same field values for different languages. If values already exists then you need to manually set language from und to en then duplicate the whole table and set the new language from und to your desired` for example 'hy' => 'Armenian',...


0

If you want to render a properly formatted single field of a referenced entity you'll simply have to use the |view filter on the desired field of the referenced node. Let's say the field_customer on my parent node references a customer content type entity that holds the customer's address in field_address. {{ node.field_customer.entity.field_address|view }}...


0

Try run below code on index.php try { \Drupal::entityDefinitionUpdateManager()->applyUpdates(); } catch (EntityStorageException $e) { print_r($e); }


0

Try $node = Node::create([ 'type' => 'calendar_data', 'title' => 'testing finaly 1111111111111111111111111 ', 'field_current_month' => date('Y-m-d'), 'field_date_type_value' => ['value' => '1'], ]); $node->save();


4

Although normally you render paragraphs recursively, you can retrieve a fixed structure non-recursively by recreating it with foreach loops: foreach ($node->field_paragraph->referencedEntities() as $paragraph) { foreach ($paragraph->field_media->referencedEntities() as $media) { ... } } This avoids accessing empty fields and is able to ...


4

Suggestion, create a domain object that has the logic. Normally these entities represent something that fits your business-domain. E.g in your instance, the node might be an event. So you might model a domain object called EventWrapper. <?php namespace Drupal\my_domain; use Drupal\node\NodeInterface; use Drupal\media\MediaInterface; use Drupal\file\...


0

A config entity is useful when there need to be multiple variations of the configuration, think views, image styles, or node bundles. If there is no need to create variations, as in system.site which stores the site's basic information or core.extensions which stores the list of enabled modules, a basic config entry is appropriate.


0

Here is a concrete example of what code needs to be written so that when hitting a url such as : www.my-website.com/my-pretty-alias You actually display the content of the following page : www.my-website.com/my-technical-needed-path/such-as/node/8 but my-pretty-alias is displayed in the url bar In my_module.services.yml file : services: my_module....


1

So the question is how to insert something like [node:5:teaser] into a formatted text area and get the teaser view of node 5. This can be done with a combination of modules: Token Filter (D7,D8) Token Filter is a very simple module to make token values available as an input filter. So (after adding that filter to the text format), for the current node, ...


0

Your missing link is the entity function, which returns the referenced entity object: $host_entity->host_field->entity->remote_field->value


0

Here is a solution for converting article nodes into a blog type. I tried Convert Bundles suggested in another answer, but wasn't able to filter which nodes to convert. With this, you can add additional conditions to the query, such like a taxonomy term value. $query = \Drupal::entityQuery('node') ->condition('type', 'article') $results = $query->...


1

The parameter should be the machine name of the entity, then it will be upcast to an entity object.


0

This line prints the attributes in plain text: {{ attributes.removeClass(classes) }} If you want to remove classes without printing then use set: {% set attributes = attributes.removeClass(classes) %}


0

How do I get a plaintext list of tags from a multi value entity reference field? $tag_names = []; foreach ($node->field_tags->referencedEntities() as $term) { $tag_names[] = $term->getName(); }


0

You can get the array of reference entities from node using $node->get('field_tags')->referencedEntities(); So the code will look something like below: // Get the referenced entities $tags = $node->get('field_tags')->referencedEntities(); // Check if we have output. (Assuming we get an array, You will have to check what your output it.) if (!...


0

I had difficulties doing this too. The trick is to use getEntitiesToView() indeed. To get the function working, the following use statement is essential: use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase; Full code for the formatter can be found here: https://stefvanlooveren.me/blog/show-file-description-custom-formatter-drupal-8


0

The solution to this problem is to load the group content from the node to which the field entity is attached. // This field is a node entity $node = $items->getEntity(); $type = $node->bundle(); $group_content_types = GroupContentType::loadByContentPluginId("group_node:$type"); $group_content = reset($group_contents); This same logic also works for ...


3

I'm not sure if there's a shortcut for that, but if not the steps are still quite minimal: Sub-class the \Drupal\user\Entity\User class in a custom module, and override its label() method: mymodule/src/Entity/User.php namespace Drupal\mymodule\Entity; use Drupal\user\Entity\User as CoreUser; class User extends CoreUser { public function label() { ...


0

This is a generic question, so my answer will be generic too. First, inserting email addresses of users to grant permissions is not a standard Drupal way, you have to have an entity reference pointing to the users. If you are using Drupal 7 you can use flexi access For Drupal 8 you can find a previously answered question here


1

You should be able to get the author like this: {{ paragraph.field_blog.entity.Owner.name.value }} and the creation: {{ paragraph.field_blog.entity.createdtime|format_date('medium') }}


0

I looked at realname module, which autocompletes the real name. Since realname stores the user defined DisplayName equivalent in the database, it can issue % LIKE queries and autocomplete on both username and realname. I posted this question to see if there were other approaches, the realname module validates the proposed method as asked in the question.


0

Something like: if ('entity.node.canonical' == $link->getRouteName()) { $params = $link->getRouteParameters(); $nid = $params['node']; }


1

Simple solution of your problem: public function build() { $message = \Drupal\contact\Entity\Message::create(['contact_form' => 'feedback']); return \Drupal::service('entity.form_builder')->getForm($message); }


1

You must call ->entity to get the file entity, then you can call ->id() like this, $userprofile->field_usr_avatar_img->entity->id().


0

You probably need to work more in UI to configure what is in {{ content }} and then render the fields as they are. If still necessary you can use {{ node }} respectively {{ paragraph }} to access all field values, see How to retrieve value of hidden field in twig?, but you can't access the url directly. You have to build this with the help of the raw ...


0

Checkbox fields value check in Twig templates for drupal 8: {% if node.field_checkbox['#items'].value == '1' %} <div class="only added when there are values"> {{ content.field_name }} </div> {% endif %} Thats works fine for me.


Top 50 recent answers are included