Questions tagged [entities]
Nodes, comments, taxonomy terms, and users, in the terminology used since Drupal 7, are generally called "entities."
8,714
questions
0
votes
2
answers
63
views
How to store a safevalue of a field in addition to the original?
I have a custom field type that I create with a custom module. It is a plain text field where the user type in a string. I want to retain two copies of this field:
The exact string value as typed by ...
1
vote
1
answer
497
views
Add tab for custom entity type on content page
I made a custom entity type and I'd like it added to the tabs on the content page seen below.
My custom_entity.links.menu.yml Looks like this
entity.custom_entity.collection:
title: 'Custom ...
0
votes
1
answer
28
views
Access FieldItem object from Widget
I have a custom FieldItem with a method doing a calculation on the field's values:
class MyFieldItem extends FieldItemBase {
...
public function getAmountInEuros() {
$amount = $this->get('...
2
votes
0
answers
376
views
How can I extend Serializer to handle a custom field type?
I'm trying to extend Serialization to get the JSON Field module to return a JSON object instead of stringified JSON.
Goal: When I access an entity that contains a JSON field using JSON:API, I want a ...
0
votes
1
answer
78
views
Generate Link based on custom content field types
I am using Drupal 8.9.8 and I have created a custom content type with field types such as plain text, number (integer), and so on. Then, I created Content based on the custom content types and filled ...
0
votes
1
answer
802
views
Get an entity URL, not its path alias
How can I get the URL of an entity without its alias?
This code just gives me the path alias, but what I actually want would be, for example, /en/node/1 instead of /en/node/my-title.
$entity->toUrl(...
1
vote
1
answer
55
views
Meta content type
Drupal core allows creating content types. I wish to have several different content types, all with the same structure.
For example:
Food
Italian food
Sicilian food
Each content type would share the ...
0
votes
2
answers
435
views
How to hide the fields in manage display when layout module is installed and display when module is uninstalled programmatically?
In the below config I want to remove the body field from content and add it in hidden as body: true when I uninstall the layout module.
Basically when I install the layout module the fields in manage ...
1
vote
1
answer
263
views
Custom theme function for a Field
I want to change a theme hook for one field from a custom FieldFormatter. It's #theme callback is 'field' but I want to give the user the option to toggle a setting that changes this to 'field_raw', ...
0
votes
1
answer
56
views
Entity agnostic way of retrieving title
Is there a way of the Title/Label/Name of an unknown entity type via 1 method?
At the moment if it's a node, I have to use $entity->getTitle(), for a user it's $entity->getAccountName(), for a ...
0
votes
1
answer
27
views
Why don't users with the "Create new content" permission for a custom bundle cannot access /node/add, but they can access /node/add/author?
If I give to a custom role the Article: Create new content permission, users can access the /node/add page. However, if I give the same permission for a custom bundle, for example Author: Create new ...
0
votes
1
answer
945
views
Programmatically add value to multi-valued/repeater field at weight/index
In Drupal 8, I have a content type and more than a few nodes that have a Paragraph field with unlimited number of values, and so I need to programmatically add a paragraph at an index to the existing ...
0
votes
2
answers
45
views
How to display a content-management-system-agnostic contact form I have developed, just without iframe?
I have developed a simple, content-management-system-agnostic[1] PHP-HTML-JavaScript-CSS contact form which I normally embed by iframe but I no longer want to use iframe due to the form appearing ...
0
votes
0
answers
54
views
How to Update Multi Value Entity Reference Field Programatically [duplicate]
I have two Node Content Types type_a and type_b I have a field called as field_author_profile in type_a which is entity reference field to type_b with cardinality unlimited.
How do I update ...
1
vote
1
answer
275
views
How can I inject services into my entity bundle class?
I have an entity with a JSON field, and I do some complicated processing when the entity is saved.
Right now, I do this processing in hook_ENTITY_presave(), which calls a service I have created in a ...
0
votes
2
answers
126
views
Best practice for getting field values of entity chains
I really would like to make this if/else field value check just a little bit more sexy.
What's Best Practice for dealing with nested functions chains to get entity field values (check if they exist / ...
1
vote
2
answers
399
views
Custom entityquery sorting
I have a normal "surname" and "firstname" fields, however I need something more than
->sort('field_surname', 'ASC')
->sort('field_firstname', 'ASC')
The surnames are old ...
-2
votes
2
answers
433
views
Inline Entity Form: alter autocomplete
I need to alter the display of the "Add an existing node" autocomplete response:
Add the content type and some more information form the content (location), display the result on two lines.
...
2
votes
1
answer
592
views
Shouldn't hook_update to add a new field to an entity use the field definition from the entity class?
I was writing an update hook to add a new field to a custom entity and was following the pattern shown here
https://www.drupal.org/node/2554097
/**
* Add 'revision_translation_affected' field to '...
1
vote
1
answer
813
views
How do I programmatically create an entity type from the install yml file?
I'm currently writing a module. In an update, I need to programmatically create a new entity type.
I have already created a suitable yml for installation. Like this one, except it is not a Node Type ...
3
votes
2
answers
198
views
String substitution in Views Contextual filter parameter?
In Drupal 9, I have a View called News.
The View is displayed at the following path:
/news
I can edit it at the following path:
/admin/structure/views/view/news/edit
It has the following Contextual ...
0
votes
1
answer
126
views
How to add the domain to the Link field?
I activated the Link module that is part of Drupal core. I want to add on the user profiles fields with links to social pages and limit the domain used in the link.
How can I add such restriction to ...
0
votes
1
answer
230
views
How can I alter an order item field depending on inline entity form (IEF) validation?
I extended my order item type with an additional boolean field.
Before the order item gets submitted via "order edit form" (/admin/commerce/orders/{order_id}/edit), it should be validated ...
0
votes
0
answers
92
views
How do I set an incremental property on a custom field?
I built a custom module which creates a custom field type (with formatter and widget), and I would like to make one property of the field incremental (to increase its value by one for each instance of ...
0
votes
1
answer
588
views
programmatically get child nodes referencing parent by entity reference uuid, using loadByProperties & entityTypeManager or other way without views
I tried this answer:
https://drupal.stackexchange.com/a/298084/1082
But I can't seem to use
'field_scientists' => $entity_reference_uuid
where, in my case, field_scientists is a field of type ...
1
vote
0
answers
39
views
Get all entities with more than one reference in a field
We have an entity type "mandate" which references to an entity "fraction membership". When a politician changes his fraction during an active mandate a new fraction membership ...
0
votes
2
answers
106
views
Is possible to find the "original" route while executing code from a widget?
I'm on D9.
I've a node edit form with a media field using the media library widget.
When a new media is added I'd need to run some custom code to replace one token, of the media path location, ...
0
votes
2
answers
136
views
Checkout Flow Submit Pane Form Checkbox to Boolean Field
I create a Checkbox in the Checkout Flow, CheckoutPane. How i can send the Value of the Checkbox to a Entity in the User-Profile or the Order.
Description: I need a Checkbox in the CheckoutPane, when ...
0
votes
0
answers
148
views
How do I get the values of multiple fields?
I'm using Drupal 9 and created a module for a custom schema.
Is there a way to simply get all the values for entity fields?
Is it efficient to access each value one by one?
2
votes
1
answer
2k
views
How do I get the names of the tables where field data is stored?
In Drupal 7, one was able to retrieve the physical names of the database tables using some code like the following, it was pretty simple.
$field_definitions = field_info_fields();
foreach ($...
1
vote
1
answer
158
views
Entity access handler causing "The controller result claims to be providing relevant cache metadata, but leaked metadata was detected."
I'm writing a custom entity access handler for a custom entity that checks if a user has access to the underlying node. The checkAccess() code looks like this:
$uuid = $entity->uuid->getString();...
0
votes
1
answer
310
views
Base field defined as entity reference with cardinality unlimited, only allowing one entry
I have defined a custom entity type "Event" and I want a field on it called "Attendees" which should allow the user to enter multiple attendees.
I have defined the field thus:
$...
-1
votes
2
answers
98
views
What problem does the entity reference module solve?
From the relevant documentation in drupal.org:
Provides a field type that can reference arbitrary entities
That doesn't help understand the purpose of this feature and what problem it was created to ...
0
votes
0
answers
23
views
How can I programmatically insert data (rows) to a custom entity table? [duplicate]
I am using Drupal 9 and I am somewhat of a newbie.
I have created a custom entity into which I wish to log the date and number of image downloads.
I can use the entity's form to create entries but I ...
0
votes
0
answers
42
views
Programmatically reset the selected elements of an entity browser widget
What I am trying to do, when the value of a field changes, reset and show the original selection widget.
For example:
1.- The first time the browser widget is displayed.
2.- After having added an ...
0
votes
1
answer
750
views
Accessing a Paragraphs field's from inside the parent paragraph
I have a paragraph twig file that I'm adding to my subtheme.
Inside of it I have another paragraph that is being used. And there could be more than 1 of the child paragraph.
I have this code:
{% for ...
0
votes
2
answers
50
views
How to achieve this? (because I think it's not possible to reference a vocabulary)
I'm trying to implement a (i think it's not that complex) functionality but I'm stuck at this moment.
I'm using Drupal 7 and I have my own custom module so, if necessary I would code, but for now I ...
3
votes
1
answer
220
views
Pass arguments to the entity_browser iframe url (modal)
I have a form I have a field of type Date Range, I also have another field of type entity_browser(modal) with a selection view widget.
The normal behavior when I click the Button of the entity browser ...
0
votes
1
answer
69
views
user account custom fields list of boolean type
In configuration form i need to create field with dinamic options. this needs to be rendered from user acount custom fields (i have create custom field earlier type of boolean) so i need reneder this ...
1
vote
1
answer
222
views
Get field value from multiple entities at once
I have a Drupal site using paragraphs in which one of the content types, let's call it a Group, can contain any number of paragraphs, and each of these paragraphs, let's call them Members, contains a ...
2
votes
0
answers
120
views
How can I update an entity with a .yml file?
I see that EntityDefinitionUpdateManager::applyUpdates() has been removed.
Every time I add a new field to a .yml file or I add a new node.type.yml to the configuration directory in a module I am ...
-2
votes
1
answer
40
views
How to implement a social media feed [closed]
I am creating a social media app and basically need a page that is a form with fields for the users to fill out and add a new post to their feed (form connects to the feed).
More detail:
The form ...
0
votes
2
answers
512
views
Perform entityQuery with multiple fields conditions on referenced fields
I have an article node type with a field referencing related articles.
If an article has less than 4 references for that field, I need to search for other articles which
are not the current node
have ...
0
votes
1
answer
112
views
How to use datelist in a custom field widget?
Since an administrator of the website I am building is visually impaired, I need to create a custom date field widget rather than use the one provided by Drupal.
I am trying to implement a datelist ...
0
votes
2
answers
324
views
How do I use DependencySerializationTrait?
I'm on Drupal 9. I'm trying to edit the ProductVariationAccessControlHandler class of Commerce.
The class extends Drupal\Core\Entity\EntityAccessControlHandler which in turn extends the abstract class ...
0
votes
2
answers
883
views
"Mismatched entity and/or field definitions" after enabling contributed module
I installed the Rabbit Hole module in Drupal 9. I was immediately greeted with this message on the status page:
Mismatched entity and/or field definitions
The following changes were detected in the ...
0
votes
1
answer
40
views
create a child node via api
Running Drupal 9.3, I have two content types, job and and Job detail. Every job has many job details.
Lets say i created a job with node ID of 5. I have a field in job detail called "field_job_id&...
1
vote
0
answers
28
views
EntityReference display french item when no english translation
Ok... Maybe I don't understand the correct way to do this, but...
I have a (translatable) entity (entity1) with a entity_reference field embed by code (declared with baseFieldDefinitions method). This ...
1
vote
0
answers
105
views
Entity Reference View as a 'Content' Field Select List only shows the last item
I have a view that gets values from a series of paragraphs in a node. The view works, and shows a list of all of the values for a field, in each of the paragraphs.
I have an entity reference view, ...
1
vote
2
answers
212
views
Set entity field to read-only after user input
I am using hook_entity_presave() to check some conditions and set field value. I would like to set the field to read-only after all conditions pass and the value is saved to database. Is it possible ...