Questions tagged as ['entities']

Nodes, comments, taxonomy terms, and users, in the terminology used since Drupal 7, are generally called "entities."
Score: 0
Lambic avatar
Entity reference field dependant on other entity reference field
ph flag

Drupal 9.

I have a content type with two entity reference fields.

The first entity reference field references group entities provided by the group module.

The second entity reference field references nodes of a certain type.

I want the second autocomplete to only find nodes belonging to the group selected on the first entity reference field.

What's the easiest way to accomplish this?

Edit: Still haven ...

Score: 1
Jean da Silva avatar
Custom Entity "changed" field is unknown
cn flag

I'm having a problem I really don't know how to solve, and need your knowledge. I have a custom entity that someone created, and forgot to add the "changed" field. So the objective is to add this field, and updated all entities to set the "changed" field to be equal to the "created" field.

Somehow even if I've updated the entity inserting this changed field, the database shows it, and when dumpin ...

Score: 1
dwienecke avatar
Two step entity reference selection
vn flag

I want to create a two step entity reference selection in Drupal 9.

The structure so far:

Content Type: Company

--> Entity reference: Jobs (multiple)

Content Type: Job

--> Entity reference: Qualification (multiple)

Content Type: Qualification

I created an import for the company profiles and there is a entity reference for multiple jobs. This is already working.

In a second step there should ...

Score: 1
Giuseppe avatar
How to hook on paragraph deletion?
br flag

I'm on D9 and I've a paragraph inside a content type node.

I need to hook when the paragraph is deleted to do some custom logic and set up a queue.

I've tried hook_entity_delete, hook_entity_predelete or hook_paragraph_delete, hook_paragraph_predelete: those hooks run during cron, if the node containing the paragraph is deleted.

However, it seems to me those aren't triggered if an existing paragraph ...

Score: 1
mathieu avatar
How to display the parent taxonomy term of the "Tags" field?
mw flag

On my Drupal 9 site, I created taxonomy terms in the "tags" vocabulary (the vocabulary and the default field of the "article" content type) :

enter image description here

When I create a node, I select a taxonomy term in the form (for example "ICO"). The node displays the "tags" field :

enter image description here

I want that if the node has the term "ICO", it also displays the parent terms. Like this :

Catégories : Culture geek, crypto, ICO

How can ...

Score: 1
Can't save value of custom datetime field
in flag

I'm reaching out because I just can't find out why my custom datetime field isn't saving its value after I submit.


I've created a field containing two datetime fields. I will use it to add or remove events from an event list, depending on whether they have passed or not (for example if a festival is scheduled from the 12 to the 14 of December, the event will be removed after the 14th).

Events in  ...

Score: 0
Giuseppe avatar
How get the referenced entity inside a field link?
br flag

I'm on D9. I've a paragraph with a Link field. I need to get the referenced entity programmatically.

What I've managed so far is:

       $nid = NULL;
       $field_link = $paragraph->get('field_link')->first();
       $route_params = $field_link->getUrl()->getRouteParameters();
        if(isset($route_params['node'])) {
          $nid = $route_params['node'];

       if($ni ...
Score: 1
How do I get the selected image style from a referenced media field?
cn flag

I created a custom block with an entity reference to a media field (field_background_image).
In the display settings I have chosen 'Thumbnail' as format and selected a custom image style 'background'.

In my _preprocess_block(&$variables) function I would like to get the selected format (thumbnail) and especially the selected image style ('background').
How can I load both these information from the $v ...

Score: 0
Baud avatar
How to get the revision of a paragraph
sa flag

I have a code which is running in hook_node_update. This code grab the revision of the saved node and compare the values of the fields between current node and its revision to generate some kind of historic log (what is deleted/updated/added).

This is working very well except for the paragraph field... When my code is trying to get the revision of a paragraph (recursively), I got each time the same para ...

Score: 6
How can I remove default image from image fields?
ru flag

I need to create an image field with a default value, which must also be nullable on single content entities. Contrary to text fields or entity reference fields, I was unable to remove this default value on single content entities.

E.g. I can create a text field with default value "Lorem ipsum". On node creation, the field is prefilled with that text, but I can also delete that text and the field ...

Score: 2
Baud avatar
How to alter the view behind a select widget in a regular node edit form
sa flag

I have an entity_reference field in a content type: field_node_ref

In the field definition, it can reference all the nodes of a given type.

The widget used for this field is a select widget

Depending the context, in the node edit form, I would like to use different views to populate the #options of the select widget.


Context A --> View A will be used

Context B --> View B will be used

The cont ...

Score: 0
jfc avatar
Is there a way to duplicate existing fields instead of manually creating new ones?
us flag

I am using Drupal 9 and I have a template which will require 40 text fields and 20 image fields.

They are meant to display 20 individual products, so they are all similar. The display would be something like this -

Product Title 1 Product Thumbnail 1 Product Subtitle 1

Product Title 2 Product Thumbnail 2 Product Subtitle 2

And so on for 20 products.

To add this field manually will take a very long  ...

Score: 1
tis avatar
How can I programmatically render the summary of a textfield?
br flag

I can output a textarea field with the following code:


How do I need to change that code for getting the summary of that field?

(Where can I find a documentation of that view-function?)

Score: 0
Kevin avatar
Deleting a Paragraph Item results in AJAX POST error "Missing bundle property on entity of type node."
in flag

Working with an older D7 site. On it, we have added the latest version of Paragraphs to add some content items to a page. This all works fine.

However, when trying to remove a Paragraph Item from the form, you get an AJAX error. The root of it is:

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 8006 of /mnt/www/html/moswebsandbox1/docroot/include ...
Score: 2
How to add Rabbit Hole to a custom content entity
kp flag

We use the module Rabbit Hole for nodes and terms. Now we would like to use it also for our custom content entities. I have tried to find some information, how to add the Rabbit Hole to a custom content entity. I have found some related information, but maybe there is some manual, which would be more specific.

I have found:

Score: 0
Get all entity reference options from a field name
in flag

I would like to create a node programatically and one field field_supervisors has an entity reference field for the node type People.

In order to set the correct entity reference information I need to set:

  ["target_id" => 1],
  ["target_id" => 2],
  // etc..

How can I get the individual id of the entity reference from the field_supervisors. Do I really need to look up the node People

Score: 0
Bulk assign content to Book
cn flag

I've decided to reorganize my site to use the book module. How do I bulk move specific content types to be children of a book?

Bulk Update Fields doesn't include the Book meta data, so I am unable to update that way.

Score: 2
Giuseppe avatar
How get the view mode\third_party_settings of a field inside hook_preprocess_image_formatter(&$variables)
br flag

I'm on D9.

I've added a custom option to the image field formatter following Drupal guidelines

In the preprocess of the field I can get the settings I've created:

function my_module_preprocess_field(&$variables) {
  if ($variables["element"]["#formatter"] === 'image') {
    $entity = $variables['element']['#object'];
    $view_mode = $variables['element']['#view_mode'];
    $field_name = $variables[' ...
Score: 0
andileco avatar
How can one programmatically get the bundle constraint for an entity reference field?
rs flag

I'm working in the context of a Views plugin. I have $entity_type and $field, as required in the snippet below. How can I get the bundle constraint for the entity reference field programmatically?

/** @var Drupal\field\Entity\FieldStorageConfig $field_configuration */
$field_configuration = FieldStorageConfig::loadByName($entity_type, $field);

$field_configuration->getType() gives me "entity_referen ...

Score: 1
Giuseppe avatar
How get webform translations programmatically?
br flag

I'm on Drupal 9. I need to load the options labels of a Webform's option programmatically.

So far, I've managed to load the labels:

  $element = $webform_submission->getWebform()
      ->getElement($element_key, TRUE);

  $option_text = WebformOptionsHelper::getOptionText($element_value, $element['#options']);

However, I also need to get those labels for both the language of the site - en and

Score: 0
Read entity reference node field
in flag

I have a referenced entity named - field_cp_level2_ref_level3. This field belongs to level3 content type. when I dump the $entity, I see the field as below:

entity:node:level3::field_cp_level2_ref_level3 => Drupal\Core\Field\EntityReferenceFieldItemList (9) Depth Limit

how to read the value of this field? I tried to read the value as below:

$var =  $entity->$node->field_cp_level2_ref_lev ...
Score: 0
quantumized avatar
Is it possible to convert a text field to an email type field that has exiting data in Drupal 9?
ng flag

We have a Drupal 9 site that has a plain text field with existing data that was used for email data. We'd like to convert this field type to email. Is this possible?

Score: 1
awm avatar
How to use entityQuery with custom field type?
mx flag

I am working on building a query for nodes that have a few custom fields (field types). The fields are custom build in a custom module with a custom schema. When I execute the query:

 $query = \Drupal::entityQuery('node')
    ->condition('type', 'place');
 $query->condition('my_custom_field', '', '<>');

It fails with a message indicating that: node__my_custom_field.my_custom_field_va ...

Score: 0
How do I know what properties and methods are available to an entity_metadata_wrapper object?
us flag

It may be easiest to start with an example.

The entity_metadata_wrapper() function seems to do a lot of complex magic behind the scenes in order to return an object with all data related to the entity in question. But how do I know what properties and methods are available to me once the object is returned?

Let's say I have Commerce Order. (This is not necessarily a Commerce question, it's just good ...

Score: 2
Ed Coakley avatar
EntityQuery where multi-value field contains a value
de flag

I've been programming for 15 years, 10 with PHP, but on my 1st Drupal project. Using Drupal 9.

I'm trying to retrieve an entity (custom content type) that has 2 multi-value entity (user) fields. If the value I have is in one field I want to get the other one. The problem is I can't figure out how to ask for the entity when the scalar value I have is in the list. Here's what I've got:

return \Drupal::e ...
Score: 0
Nathan Zim avatar
Build custom form with entity form field
de flag

I have a feature to migrate from Drupal 7 to Drupal 9. This allows me to build a custom form made up of static fields, which I define in the code of my module, and fields dynamically retrieved from an entity.

It worked with the "ctools_field_invoke_field function", which relies on the Chaos Tools module. This function is itself based on a native Drupal function "field_default_form".

This function wa ...

Score: 0
hotwebmatter avatar
Set ['#default_value'] of taxonomy term reference field via hook_form_alter()?
nr flag

Here's a different question with the same taxonomy term reference field I mentioned in my previous question.

Users with Administrator and Coach roles are granted permission to register Student users via a custom "Add student" form mode (user_add_student_form). It would be better for UX if I could set the ['#default_value'] of the select_a_school taxonomy term reference field to the same school that  ...

Score: 1
hotwebmatter avatar
ConstraintValidator fails to validate constraint on Taxonomy Term reference field
nr flag

Client has a simple and consistent hierarchical taxonomy.

Cities at the top level and Schools at the second level.

├── City1
│   ├── School1
│   ├── School2
│   └── School5
└── City2
    ├── School3
    └── School4

The User account entity bundle contains an Entity Reference field to the School taxonomy terms.

I am trying to enforce a constra ...

Score: 0
Stef Van Looveren avatar
Where to define custom entity caching rules of detail pages
cn flag

When you have a larger project you probably have both internal page cache as internal dynamic page cache module enabled. In my case I do. But I have a section on my website containing custom entities ('Contest') where I would like to have custom-tailored control of caching of the detail page (contest/1). This is what I found so far:

 * Implements hook_entity_view_alter()
 * Disable caching on a ...
Score: 1
Is it possible to use a subquery in an entity query?
ai flag

How can I add a condition to a Drupal 9 entity query using another entity query on a different entity type?

I'll illustrate the question by describing one specific use case, though I don't think it would be difficult to come up with any number of plausible use cases.

The application for this use case tracks articles in published medical literature. An article is represented by a custom entity type w ...