Questions tagged [entities]

Nodes, comments, taxonomy terms, and users, in the terminology used since Drupal 7, are generally called "entities."

Filter by
Sorted by
Tagged with
1 vote
1 answer
551 views

How to send a contact form via JSON:API?

What are the requirements for submitting the contact form using JSON:API? I enabled the core Contacts module and set up a custom site-wide contact form. I gave permission to anon + auth users to ...
Patrick Kenny's user avatar
1 vote
0 answers
100 views

How do I display field from one content type in another content type

I am working with Drupal 9. I found other questions similar, but I do not understand what they are saying to do, and they are 10+ years old so I do not know if they still apply. Maybe the best way to ...
kjmeyse's user avatar
  • 11
0 votes
0 answers
30 views

Do something when a content is saved

I'm a total beginner in module coding and i'm trying to adapt a simple D7 module which is updating a field from a content type from an external API when the content is created or modified. On an fresh ...
smeys's user avatar
  • 1
0 votes
1 answer
93 views

How can I set validation rules on my entity fields and get errors if the data isn't valid

I have this entity which got the link field This link is mandatory, has to be more than 3 chars and less than 255 Also it has to be a valid URL class Myentity extends ContentEntityBase implements ...
beta-developper's user avatar
1 vote
1 answer
67 views

How do I control config names?

When creating a config entity, we get an example_entity.schema.yml file: example_module.example_entity.*: type: config_entity label: 'Example config' mapping: id: type: string ...
KrzysiekK's user avatar
2 votes
1 answer
185 views

How can I specify the relation type between two entities?

I am new two Drupal Trying to create two entities, Post and Category (This is for tests purposes) A Post can have one Category, and a Category can have multiple Post Here is my implementation of the ...
beta-developper's user avatar
1 vote
1 answer
98 views

How to make media description show on form view when used as entity reference

Drupal 9... I have a content type of "Resource" which uses a field "download" which references the media type "document", but when I upload a file to the field, it gives ...
wotney's user avatar
  • 202
0 votes
1 answer
68 views

Entity reference link: add reference from Entity B to Entity A

I have created 2 Content entities. Entity A has an "Entity Reference Field" with multiple values to Entity B. This all work as expected. What I want to achieve is, to create a link from ...
cateye's user avatar
  • 733
0 votes
0 answers
63 views

How can I filter based on unique taxonomy term values?

I have a content type "book". One of its field "field_language" referencing to "language" taxonomy term. field_language can have only one value. Consider this is the ...
Steve Siddu's user avatar
1 vote
1 answer
149 views

How do get a value from field in if/else statement

In a custom views-view-fields.html.twig I do print a list field (field_status) without issues. The values are: new|New old|Old But if i want to do an if/else statement for printing different div ...
druplash's user avatar
0 votes
1 answer
142 views

How to completly remove a field?

I have removed a field from a bundle (it is not used somewhere else) by using the graphical UI. But it is still listed when I run the following command (after cache clear) $this->entityFieldManager-...
Baud's user avatar
  • 570
2 votes
2 answers
577 views

Why do setter methods in an entity return $this?

Writing a custom entity type I noticed that all setter methods in entity classes are returning $this after changes, as methods modify the object and so object will definitely being modified, then ...
Alireza Tabatabaeian's user avatar
2 votes
1 answer
386 views

Programmatically find out field name of an Id-field

Depending on the type of entity, it is either nid/vid/uid and possibly other. It is nice to have an ->id() method which allows you to work with data in an uniform fashion without relying on those ...
informatik-handwerk.de's user avatar
0 votes
1 answer
105 views

How to remove the fieldsets that are pup around "list (text)" fields that have their display set to "Check Boxes / Radio Button"?

We have a Drupal 9 website and are using "list (text)" fields whose displays are set to "Check Boxes/ Radio Button". This causes the output to be wrapped in a field set which we ...
quantumized's user avatar
  • 1,177
2 votes
1 answer
172 views

Unique constraint on several entity fields fails when >1 jsonapi POST requests happen right after another

In a fully decoupled drupal 9 project I have a custom entity type and added a unique constraint for several fields just as described here. This works well and adding a second entity with the same ...
theuni's user avatar
  • 845
1 vote
1 answer
171 views

Theming a EntityListBuilder.php table using drupal/examples/content_entity_example as base

Any idea how I could to use my own custom module twig file to theme my table? I'm using drupal/examples -> content_entity_example as a starting point: in content_entity_example.module implementing ...
user14409370's user avatar
0 votes
1 answer
208 views

How to copy fields from an entity to another for same type entities?

I have 2 entities of the same type & bundle but used in 2 different cases (linked differently to different entities). Upon publishing the second entity, I want to get the new data and put it into ...
Lia's user avatar
  • 121
2 votes
1 answer
73 views

Number field type for specific format

I have to store number data into database in format xx-xxxxxx-xx for example I have xml data in format: ISBN="10-000000-701" ISBN="11-000000-002" ISBN="11-000000-004" and ...
lazarcelic's user avatar
2 votes
1 answer
60 views

Connect field with Taxonomy Term

I have taxonomy Brand and different fields like RAM, Monitor, 'CPU' under content-type Hardware. While adding a new Hardware how can I add RAM, CPU or other fields with Brands? e.g. RAM = 16 GB, Brand ...
shyammakwana.me's user avatar
0 votes
1 answer
137 views

Custom reference field saving empty values

I've created a custom field based on entity reference field but the target_id it saves comes from an external system. I have the field type, field widget and autocomplete element defined and working ...
Lambic's user avatar
  • 708
0 votes
0 answers
37 views

How do I add a revisions tab to a custom content entity and list revisions? [duplicate]

I'm trying to achieve exactly what's described on How to add revisions tab to a custom content entity and list revisions? I created my custom entity using Drush, and set it revisionable: Doin that, I ...
Ramon Roca's user avatar
1 vote
1 answer
1k views

EntityQuery condition only if field exists

How to apply a condition only if a field exists? $query = \Drupal::entityQuery('node') ->condition('type', 'videos') ->condition('field_tags', 39, '=') ->condition('status', 1) ->...
Nicolas E's user avatar
2 votes
0 answers
33 views

How does Postgres manages case-sensitive versus case-insensitive “IN” operations in Entity Queries?

I see that an equality is converted to a LIKE operation when the field is tagged as case-insensitive, which Postgres then translates to ILIKE in the driver. However, I don’t see how Postgres is able ...
Kevin Nowaczyk's user avatar
0 votes
1 answer
220 views

How to remove a spurious entity update?

Something (I'm not sure what) has introduced what appears to be a spurious entity update into my Drupal 9 site. I'd like to delete the update so that I'm no longer prompted to apply it. > drush ...
tparks53's user avatar
1 vote
1 answer
153 views

Entity reference auto complete field is missing value on ajax callback

I have an entity reference field on my content type using the autocomplete widget. I'm adding an ajax callback to that field using this in a form alter: $form['field_er']['widget'][0]['target_id']['#...
Lambic's user avatar
  • 708
0 votes
0 answers
126 views

Entity reference field dependant on other entity reference field

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 ...
Lambic's user avatar
  • 708
1 vote
1 answer
224 views

Custom Entity "changed" field is unknown

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 ...
Jean da Silva's user avatar
1 vote
0 answers
50 views

Two step entity reference selection

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: ...
dwienecke's user avatar
1 vote
1 answer
576 views

How to hook on paragraph deletion?

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 ...
Giuseppe's user avatar
  • 897
1 vote
1 answer
85 views

How to display the parent taxonomy term of the "Tags" field?

On my Drupal 9 site, I created taxonomy terms in the "tags" vocabulary (the vocabulary and the default field of the "article" content type) : When I create a node, I select a ...
mathieu's user avatar
  • 25
1 vote
0 answers
125 views

Can't save value of custom datetime field

I'm reaching out because I just can't find out why my custom datetime field isn't saving its value after I submit. Context: I've created a field containing two datetime fields. I will use it to add or ...
Dancoo's user avatar
  • 11
0 votes
1 answer
242 views

How get the referenced entity inside a field link?

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('...
Giuseppe's user avatar
  • 897
1 vote
0 answers
38 views

How do I get the selected image style from a referenced media field?

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'. ...
Mike's user avatar
  • 41
0 votes
2 answers
1k views

How to get the revision of a paragraph

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 ...
Baud's user avatar
  • 570
6 votes
1 answer
280 views

How can I remove default image from image fields?

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 ...
Hudri's user avatar
  • 5,286
2 votes
1 answer
54 views

How to alter the view behind a select widget in a regular node edit form

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 ...
Baud's user avatar
  • 570
0 votes
1 answer
36 views

Is there a way to duplicate existing fields instead of manually creating new ones?

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 ...
jfc's user avatar
  • 193
1 vote
1 answer
585 views

How can I programmatically render the summary of a textfield?

I can output a textarea field with the following code: $entity->fieldname->view(); How do I need to change that code for getting the summary of that field? (Where can I find a documentation of ...
tis's user avatar
  • 75
2 votes
1 answer
151 views

How to add Rabbit Hole to a custom content entity

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 ...
Antonín Slejška's user avatar
0 votes
1 answer
151 views

Get all entity reference options from a field name

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 ...
supersize's user avatar
  • 263
2 votes
1 answer
353 views

How get the view mode\third_party_settings of a field inside hook_preprocess_image_formatter(&$variables)

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(&...
Giuseppe's user avatar
  • 897
0 votes
1 answer
440 views

How can one programmatically get the bundle constraint for an entity reference field?

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? /** ...
andileco's user avatar
  • 299
1 vote
2 answers
615 views

How get webform translations programmatically?

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() ->...
Giuseppe's user avatar
  • 897
0 votes
1 answer
81 views

Read entity reference node field

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::...
chaydru's user avatar
  • 43
0 votes
0 answers
91 views

Is it possible to convert a text field to an email type field that has exiting data in Drupal 9?

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?
quantumized's user avatar
  • 1,177
2 votes
1 answer
638 views

How to use entityQuery with custom field type?

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:...
awm's user avatar
  • 2,429
0 votes
0 answers
33 views

How do I know what properties and methods are available to an entity_metadata_wrapper object?

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 ...
blue928's user avatar
  • 3,804
2 votes
1 answer
597 views

EntityQuery where multi-value field contains a value

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 ...
Ed Coakley's user avatar
0 votes
1 answer
1k views

Build custom form with entity form field

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 ...
Nathan Zim's user avatar
0 votes
0 answers
263 views

Set ['#default_value'] of taxonomy term reference field via hook_form_alter()?

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 ...
hotwebmatter's user avatar
  • 2,102