Questions tagged [entities]
Nodes, comments, taxonomy terms, and users, in the terminology used since Drupal 7, are generally called "entities."
8,710
questions
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 ...
1
vote
3
answers
115
views
ConstraintValidator fails to validate constraint on Taxonomy Term reference field
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
...
0
votes
1
answer
81
views
Where to define custom entity caching rules of detail pages
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 (...
2
votes
0
answers
157
views
Is it possible to use a subquery in an entity query?
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 ...
1
vote
0
answers
169
views
How to query on last delta?
The documentation for QueryInterface::condition explains how to narrow a condition to a specific delta of the field being queried. Is there a way to tell the interface to look at the value for the ...
3
votes
2
answers
166
views
AJAX Form using a sub-class of ContentEntityForm fires/invokes/calls the WidgetBase::massageFormValues() twice
I'm using a AJAX form. This form I build from a sub-class of ContentEntityForm. The Entity edited by this form has a field MyField. To bring all the field values in a appropriate structure I'm using ...
0
votes
1
answer
370
views
Gracefully handle URL/URI/Link exceptions when using Link field formatter?
Occasionally I am encountering an error along these lines:
The website encountered an unexpected error. Please try again later.InvalidArgumentException: The URI 'XYZ' is invalid. You must use a valid ...
1
vote
0
answers
143
views
Auto add content to specific entity queue dependant on chosen taxonomy term
I have a People content type, which has an Expertise field which is a taxonomy term reference field.
There will then be an EntityQueue set up for each Expertise term.
What I'd like to do is ...
2
votes
2
answers
54
views
Joining two text fields in a Computed Text field
I have two fields whose type is List (text). In the allowed values list, i want to join them. I used the following code.
$value = $entity->field_a->value . $entity->field_b->value;
$value =...
0
votes
0
answers
258
views
Programatically reorder referenced entities by field
I have a content type Speaker that uses an Event content type as reference. The Event has a start date and time field. There can be any number of events that a speaker speaks at, when visiting the ...
1
vote
1
answer
25
views
How accurate is the field list for estimating where fields are used?
I am trying to locate all places where a particular field is used. I am trying to see especially which all Views have required the field.
I was planning to do a manual search using editor Find and ...
7
votes
1
answer
664
views
What method should I use instead of Drupal\Core\Entity\Query\Sql\Query::addExpression()?
I am using Entity Query to select nodes of two different types. The fetching seems to be working, but I want to sort the returned values. Both the content types have different date fields. I know I ...
0
votes
1
answer
213
views
How do I unset an entity reference using JSON:API?
I can't figure out how to unset an entity reference (remove a reference to a term from a node) when editing content via JSON:API.
JSON to create a new node:
const myNodeToPost = {
data: {
...
3
votes
1
answer
381
views
Update FieldStorageConfig for a field in an update hook properly?
I need to update the allowed values option on an list_integer field. For reasons at the moment, I can't just update and export the configuration and import it on production until we implement ...
0
votes
1
answer
117
views
Actions form array overriding to set HTML id attribute
I extend the EntityForm class and I try to override a submission button, to set its HTML ID attribute (try #1). Since it doesn't work, I tried to wrap the button in a wrapper <div>. I tried to ...
1
vote
0
answers
298
views
Can't get field storage definition in custom entity
I have a custom entity 'myentity' with some fields, and one of them is a taxonomy field with the next definition:
$fields['colors'] = BaseFieldDefinition::create('entity_reference')
-&...
3
votes
1
answer
166
views
Details wanted for "Mismatched entity and/or field definitions" message on custom field
I have developed a custom Drupal field.
All works fine. We are already using the field in production for a year. But the status report for exactly this field says:
Mismatched entity and/or field ...
2
votes
1
answer
1k
views
How can I programmatically delete a field value?
Using Entity API, I know how to get a value or to set a value :
$nid = $entity->id();
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
...
$nom = strtoupper($node->get(...
0
votes
2
answers
924
views
How to make the float field accept decimal values?
I am using Drupal 7 and have a float field. It is used to enter prices.
Most of prices I enter have decimals (e.g. 101.82, 99.88). Some of the prices are negative values (e.g. -55.52, -1009.88).
...
0
votes
0
answers
66
views
Hook_install or hook_modules_installed save entity does not work
I am trying to insert a new vocabulary to taxonomy because a custom entity from my custom module needs that vocabulary as an entity reference. I think it would be better to always insert the reference ...
1
vote
1
answer
585
views
How can I load an entity's bundle object from a loaded entity?
If I want to get an entity's bundle object, with a node, I can do something like:
$bundle_object = \Drupal::entityTypeManager()
->getStorage('node_type')
->load($node->bundle());
But ...
2
votes
0
answers
51
views
How can I capture a field’s configs and storage so I can delete it and then re-create it?
I’m trying to implement this in a hook_update_N() but I’m not sure it’s proper (see excerpt below). Note I’m changing max_length in the process.
What I'm trying to do: update my_custom_entity....
2
votes
1
answer
192
views
Using the entity query API to identify entities with correlated values
Imagine two Drupal 9 custom entity types named a and b.
Entity type a has two fields a_f1 and a_f2.
Entity type b has a field b_a which is an entity reference with a target type of a and unlimited ...
1
vote
1
answer
29
views
Why is <my_entity>-content-add-list.html.twig template not being used?
I have generated a custom content entity via the Drupal Console. It has bundles. I would like to customise the screen which you get to when adding a new such entity - the screen which displays the ...
0
votes
2
answers
78
views
Loading content in a View via a sibling entity reference
I think what I need to do is use one Drupal View's results to filter the results of another view. Here is what I am trying to accomplish.
I have 3 content types (node types): Blog, Blog Post, ...
2
votes
2
answers
261
views
How to set a validation constraint for base fields like the taxonomy term name?
I'm having trouble setting a validation constraint on the name of the taxonomy term.
function MYMODULE_entity_bundle_field_info_alter(&$fields, $entity_type, $bundle) {
if ($entity_type->id() ...
0
votes
0
answers
463
views
Save multiple entities in one transaction
We have a custom API endpoint that handles data for multiple users. Unfortunately, we are having a performance issue because every time we save a user entity, the save operation takes 3-4 seconds to ...
2
votes
2
answers
1k
views
How do I set the default value for a user entity reference field in hook_form_alter()?
I tried the following code, but it doesn't work.
$form['field_name']['widget'][0]['target_id']['#default_value'] = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
1
vote
0
answers
42
views
entityQuery returns wrong result: too many joins?
I built an entityQuery for a custom entity type "vote". I only want to get those votes for a specific poll and those by deputies who are members of a specific fraction. The fraction ...
1
vote
1
answer
153
views
Optimal way to get a content type's field definition
When I need a content type's field definition in Drupal 8+, I used to run the following code (for getting 'body' field in content type 'page'):
$page_fields = \Drupal::getContainer()->get('...
0
votes
1
answer
68
views
Validation doesn't show an error when the value entered in the field doesn't respect the minimum length
I am using the Field validation module to validate a text field using the Length rule with a minimum length of 1.
When the field is left empty, no validation error is shown.
Setting the field as ...
0
votes
0
answers
196
views
Chained tokens for referenced custom entities
We have two custom entities: parliament_period (can be an election or a legislature) and parliament. A parliament_period entity has a reference to a parliament entity.
In a Poll node, we have an ...
0
votes
1
answer
42
views
Using radio FormElement in a drupal 8 ListBuilder
I made a custom configuration entity, and I'm trying to set up radio buttons in the listBuilder. This is done in the core module language without any problems, but when I try to do the same trick with ...
-1
votes
1
answer
60
views
How can I remove some measure units from the Physical Fields widget?
I'm trying to alter the widget for the fields implemented by the Physical Fields module, using hook_field_widget_form_alter().
I'm trying to remove some units from the select list, but there isn't a ...
0
votes
1
answer
67
views
How do I query for all the entities for which a multi value field doesn't contain a specific value?
I have a multi value field which contains plain text. This is how it looks from the edit form.
I want to fetch entities that don't contain the Expired value. How can achieve it?
This is the code I ...
0
votes
1
answer
75
views
Base fields vs Config fields?
I have an entity and I am not sure what I should use. On the one hand, configuration fields are easier to use via the UI, why should I consider base fields?
By using base fields everything is stored ...
2
votes
1
answer
77
views
Add ThirdPartySettings to individual paragraphs of a certain bundle?
I want to add configuration settings to Paragraph entities in a specific bundle in Drupal 8. Theres potentially a lot of options and the need to change/update them over time, so I figure the best way ...
0
votes
1
answer
588
views
Set a Data Value from Text field to Term Reference field
Node has two fields:
Text field
Term reference field (autocomplete?)
The Text field is old and already has 500 nodes with 500 unique values.
The Term reference field is new and needs to contain same ...
0
votes
1
answer
1k
views
FieldItemList::getValue always returns a string, even for a Boolean field
Supposed I added a custom Boolean field, whose cardinality is 1, to a content type. I create a node of that content type, enter a value for that field (for example, TRUE), and save the node.
When I ...
0
votes
0
answers
82
views
Cron is running but not saving entity
I am trying to create a simple hook_cron to connect with an external API, return some data and update some fields in some entities. I'm creating like this to understand better how cron works, so I ...
0
votes
1
answer
50
views
Entity Browser Modal closes on Exposed Filter Submit Button
I've set up a commerce shop that uses Entity Browser to select product images. I set up a view to display the selectable images which has an exposed filter for the filename, so the user can search for ...
2
votes
1
answer
74
views
Taxonomy term save very slow
I have a vocabulary with around 15k+ terms in multi-level hierarchies. Recently I noticed that with this amount of data, when I try to save a term of a higher level (parent to many), it takes a lot of ...
3
votes
2
answers
1k
views
How to create a custom content entity without canonical url?
I've created a custom content entity with drush generate module-content-entity, which works great. However, I want my custom entities NOT to have a canonical url. Drush automatically creates those in ...
1
vote
0
answers
1k
views
How to filter entity_autocomplete results by content type and a field
I am trying to implement an entity autocomplete field in a form where the autocomplete entities are filtered by content type and a certain field of that content type.
I know I can filter the ...
0
votes
0
answers
72
views
Read comment attachment name and file location
I have a view that has comment, comment attachment(as a file). I want to read the file name and it's location. View looks like below:
I am able to read the title by the below code:
public function ...
1
vote
0
answers
120
views
Create several fields from one array field
I have a Drupal View based on one entity that is pulled from another database (it is a CiviCRM entity pulled into Drupal with the help of CiviCRM Entity Drupal module).
One of the fields I use is an ...
0
votes
0
answers
44
views
Read view row entities and create a node for each entity
I have a view that looks like in the following screenshot.
I am creating a custom action to publish selected comments and create a node for each comment. The custom action code is the following.
...
0
votes
1
answer
532
views
Set the menu link description in hook_entity_presave()
How do I update the menu link description with hook_ENTITY_TYPE_presave()?
I can print out the menu link title and menu link description with the following code.
kint($entity->menu['title']);
...
0
votes
2
answers
124
views
How do I automatically fill the subject in the contact forms?
I created 2 types of contact form. I disabled Subject in Manage form. I want the fake Subject field not to be displayed in the contact form, and I want it to be filled in automatically.
How do I ...
1
vote
1
answer
203
views
Programatically create paragraphs entity form
I am in a situation where I would like to split out Paragraph entities to separate forms.
Edit forms are no problem:
$entity = Paragraph::load($entity_id);
return \Drupal::service('entity.form_builder'...