Skip to main content
The 2024 Developer Survey results are live! See the results

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
2 votes
0 answers
14 views

Show default value when field access denied

I have a hook_entity_field_access() that allows access to the user picture field in various conditions. When viewing the user, the picture is either present or not present as it should be. The user ...
Steve's user avatar
  • 21
0 votes
0 answers
29 views

Entity Reference field link doesn't respect the current site language

I have content type Text with Entity reference field field_song, that links to content of type Song. Content type Song has default language French. When I display the field_song and check the option ...
bstr's user avatar
  • 1
0 votes
0 answers
14 views

Compare workflow/moderation state in hook_entity_update()

We have a content moderation workflow with 'published', 'draft', 'submitted' and 'returned'. I am trying to detect changes to the moderation state with hook_node_update(). function ...
donquixote's user avatar
  • 3,652
0 votes
1 answer
42 views

Best practice design route for an estimates table

I need to allow users to store monthly estimates so that they can be later retrieved in our management information system. It would look something like this but with the next 12 months. The first ...
ChumKui's user avatar
  • 183
0 votes
2 answers
90 views

Deprecated EntityBlock module preventing upgrade

I have a Drupal 9.5 site that I am attempting to composerize and upgrade to Drupal10. I created a Drupal10 site in a local environment, copied the site content over, and installed all the Drupal10 ...
Justin Desmarais's user avatar
0 votes
1 answer
21 views

How to restrict access to GET with JSON:API for specific entity type?

According to the JSON:API docs, you can implement the alterRoutes() method on a route subscriber to restrict access to collections. In a custom module, I have an entity type that should be POST only (...
Patrick Kenny's user avatar
0 votes
0 answers
14 views

In ListBuilder, UUID sometimes shown for anonymous

I created a custom entity using drush generate entity:content. In MyEntityListBuilder.php: /** * {@inheritdoc} */ public function buildRow(EntityInterface $entity): array { $row = []; ...
Patrick Kenny's user avatar
0 votes
1 answer
43 views

hook_entity_bundle_field_info_alter() cannot call entity_display.repository's getViewModes()

Somewhat the continuation of Getting existing fields in hook_entity_bundle_field_info() with a similar problem. I'm using this hook now to make modifications not only to the bundle fields but their ...
Gábor's user avatar
  • 866
0 votes
2 answers
32 views

Getting existing fields in hook_entity_bundle_field_info()

I have custom fields that I need to add to specific entity types and bundles with hook_entity_bundle_field_info(). However, I have to decide on which one to add depending on already existing fields, ...
Gábor's user avatar
  • 866
0 votes
1 answer
29 views

"Route does not exist" in JSON:API for custom entity type

I created a custom entity type using drush generate entity:content. I chose to have bundles, and I added a bundle test_bundle. I can add my custom entities at admin/content as expected. However, when ...
Patrick Kenny's user avatar
1 vote
2 answers
90 views

How to get the title of a referenced entity with `?_format=json`?

I have a site https://www.huytonweb.com/ the front end is in Next.js and the back end is Drupal 10 CMS. The front end will access the data from the back end using ?_format=json (like https://cms....
Dave_____1's user avatar
-1 votes
1 answer
48 views

How to duplicate the Node entity?

I want to create a word comparison dictionary. Maybe an HTML table like the following isn't good because there are too many columns for a screen responsive table. English Chinese Japanese Korean ...
user114794's user avatar
0 votes
1 answer
22 views

How to prevent the anonymous user from being the author of a custom entity type?

I am making a module that stores push notification tokens as a custom entity type. Because of the nature of push notification tokens (sending a notification to the user's device, like an email address)...
Patrick Kenny's user avatar
0 votes
1 answer
135 views

How to inject RevisionableStorageInterface()?

I have a module I'm trying to update to Drupal 11. Here's the code: public function processItem($data) { $entity_type = $this->entityTypeManager->getDefinition($data['entity_type']); $...
Patrick Kenny's user avatar
1 vote
1 answer
58 views

Two-way Entity reference, programmatically

I'm building a custom module to handle two custom entities which extend ContentEntityBase: Organization and Contact. Organization can have multiple contacts, while contact can belong to one ...
bdereta's user avatar
  • 141
0 votes
1 answer
68 views

How to get a deep clone of an entity object

Is there a way of getting a second object for an entity that is a different PHP object (with different PHP objects inside as well)? I tried using https://github.com/myclabs/DeepCopy with a node entity ...
joachim's user avatar
  • 846
1 vote
0 answers
59 views

How to make a GET request to return Entity Registration form fields?

I am using Drupal as a decoupled CMS with Entity Registration module, and would like to get the Registration Type form fields to display on my SPA. I have enabled the REST resource: /entity/...
Brownrice's user avatar
  • 111
2 votes
1 answer
67 views

How to prevent custom field being indexed in custom entity?

I'm creating custom entities extending ContentEntityBase but when I review the created table in MySQL, it has created indexes from fields I don't want. This is and excerpt of my custom entity: /** * {...
briast's user avatar
  • 654
0 votes
0 answers
23 views

Inline Editing Weight Field on admin view

I am working on a Drupal 10 site and and I have a built an admin view that has 2 fields. Node title and Weight. I would like to be able to on that view edit the weight inline on each node and save it. ...
ThankYouNeco's user avatar
1 vote
2 answers
127 views

How to quickly delete thousands of nodes?

This appears to be the prescribed way of deleting multiple node entities: $nids = \Drupal::entityQuery('node') ->accessCheck(FALSE) ->condition('field_my_field', 'something') ->execute()...
arnoldbird's user avatar
  • 1,267
0 votes
1 answer
93 views

Use token from parent entity

In a drupal 10 site I have a content type called article with an entity reference field on it called "Related nodes". Those related nodes are of type page. On the page content type there is ...
devunder's user avatar
  • 1,194
0 votes
1 answer
95 views

Get Field Weights Programmatically

I have a custom module which ultimately creates a node of a given type. It gets the fields of that node type and creates my own form with them, HOWEVER, it does not preserve that node's order of ...
Michael D. Moradzadeh's user avatar
0 votes
0 answers
41 views

Entity upload endpoint (POST) API security

Although Drupal provides default security features, I still have a doubt related to the security of uploading a file using the file entity upload API URL. If I have set the allowed file extension and ...
Tejas's user avatar
  • 1
-2 votes
1 answer
69 views

Can I display the add content form as accordion

In Drupal 10, can the add content form for a content type be set up to show groups of fields under expandable sections? We have tried to make this work with the Field Group module but the removal of ...
Bobtail3095's user avatar
0 votes
0 answers
67 views

Change Bundle Type for Media Entity

By a mistake, a lot of videos were created as documents instead of videos. I want to avoid copy them into new entities because of the usage of the existing entities. I tried something like the below ...
NicklasF's user avatar
  • 309
1 vote
1 answer
142 views

Custom entity access control handler not being called

I'm trying to define an access control handler for a custom entity, and as far as I can tell it's never being called. Here's my entity header: /** * Defines the Target entity. * * @...
Lambic's user avatar
  • 718
0 votes
1 answer
47 views

Entity reference to role

I want to add an Entity Reference field to a Group Type entity, referencing User Roles. When I add a Entity Reference > Other > Roles field, the creation/edition form of this Group Type throws ...
raistlinjoe's user avatar
0 votes
0 answers
44 views

Render array for default values in a entity reference field not loading correctly

A comment field type in a node(rendered as a form in the node view) has a user entity reference field where multiple user entities can be input and has default values set with: foreach ($...
peebs124's user avatar
0 votes
0 answers
64 views

How do I access the overridden ALT tag with the Media Library Media Modify module?

The Media Library Media Modify module ( https://www.drupal.org/project/media_library_media_modify ) allows one to override a media item's default ALT tag so you can have contextual ALT tags with every ...
Naidim's user avatar
  • 204
0 votes
1 answer
61 views

How to programmatically add the exact name of the field in the form?

I have used hook_entity_base_field_info in my custom module to add a field to the user entity: $fields['phone'] = BaseFieldDefinition::create('telephone') ->setName('phone') ->setLabel(t('...
Mahyar SBT's user avatar
0 votes
1 answer
152 views

Unable to resolve "User ID field needs to be updated" error on status page

I'm on Drupal 10.1.6, and the above-mentioned error is appearing on my status page under "Mismatched entity and/or field definitions." I had similar errors for fields on different entities (...
JOakland's user avatar
  • 462
1 vote
2 answers
244 views

How configure the field permissions of a custom entity?

I'm on D10.x.x and I've created a custom content entity - code below. Those entities are created programmatically after an event, and one is assigned to each one of the site' users. The users with ...
Giuseppe's user avatar
  • 981
0 votes
1 answer
267 views

Get the value of a custom entity field

How can I get the value of a custom field added to user profiles? I read and tested everything I found on Google, including the following code. $user = \Drupal\user\Entity\User::load(\Drupal::...
user54375's user avatar
0 votes
0 answers
62 views

Why would Manage Display break when the content type machine name is a number?

Drupal 10.1.6 PHP 8.2.5 I am not sure how long ago it started, I just noticed it about a week ago. It only happens when the machine_name of the content type is numeric. When I go to /admin/structure/...
Jamie's user avatar
  • 65
0 votes
1 answer
70 views

How can I get the error message when a user account has not been successfully saved?

I'm trying to build a rest API to provide my mobile team to register a user using mobile app. I'm using www.example.com/entity/user for rest API as POST. I'm able to create the user, but in some cases,...
veera's user avatar
  • 1
0 votes
0 answers
71 views

Is there any way to use EntityQuery on entity_reference fields in reverse?

Let's say I have two custom entity types: entity_one, entity_many. I know how to use an EntityQuery to find entity_one matches if there is a multi-value entity reference field on entity_one. $results =...
JonMcL's user avatar
  • 627
0 votes
1 answer
41 views

Prepopulating a drop-down select box that references another entity

I have a node create form for content type "space" so that the URL looks like https://.../node/add/space. In this page, there is a form with a drop-down select that corresponds to an entity ...
BMM's user avatar
  • 103
0 votes
0 answers
83 views

Query condition with entity referenced via custom field

We have the usual way to reference related tables through JOINs using: $query->condition('foo.entity:type.bar', $value); But how can this be specified when foo is not a direct field but a complex ...
Gábor's user avatar
  • 866
0 votes
3 answers
137 views

How can I have updated content entity data immediately available after update?

I created custom content entities to handle a small NGO membership (Member, Person, both linked to Drupal 'users'). I have a form allowing users to perform online membership application. Submitting ...
gbmapo's user avatar
  • 1,086
0 votes
0 answers
73 views

How to create an entity with a referenced entity [duplicate]

I work with Drupal Commerce but my question is more related to a custom entity which refers to a custom entity. Concretely, users have a profile. This profile contains fields including a field which ...
Sébastien Gicquel's user avatar
0 votes
1 answer
729 views

Query to fetch users with specific roles

I'm using the following code. $query = \Drupal::entityQuery('user'); $query->condition('uid', [302,330], 'IN') ->condition('status', 1, '=') ->condition('field_membership_status....
jg999's user avatar
  • 11
0 votes
1 answer
74 views

How can I handle race conditions in a headless setup?

I am currently trying to build an eCommerce site. The functionalities are quite basic; there are products with limited quantities and customers can purchase those products. I've decided to use Drupal ...
levente.nas's user avatar
3 votes
1 answer
152 views

Drupal::entityQuery add CASE to have NULL values displayed last

I want to sort some entities in ascending expiration date, but I want those without expiration date to be at the end. Is there a way to add a CASE expression like this to the Drupal::entityQuery? $...
user7167081's user avatar
0 votes
1 answer
106 views

How to use node context in custom block plugin to get correct revision for node and its fields?

Background information for this question can be found here: How to have a different hero image per node? I have written a custom block that takes the data from this "hero" paragraph and ...
Jordan's user avatar
  • 49
0 votes
1 answer
233 views

How to get $form_state->getUserInput() ( i.e, what the user entered in the input ) in each inline entity form and not only in the first one?

I use the Inline Entity Form module to build nested multiple forms. I have a design form in which there is an inline form - garment. And inside the garment form, there is a product field. In the ...
nathan111777's user avatar
0 votes
1 answer
94 views

Translatable custom entity

Was there any significant change in how translatable custom entities are updated leading up to Drupal 10.1? There are a few questions here that deal with the question but it no longer seems to work. ...
Gábor's user avatar
  • 866
2 votes
1 answer
104 views

How can I get the untranslated field value from a translated paragraph?

Normally you can't have different paragraph items per language so I simply want to hide selected paragraphs depending on a field value in the paragraph. I added an untranslatable list field listing ...
leymannx's user avatar
  • 18.3k
1 vote
1 answer
283 views

Hide field programmatically in "manage display"

I develop a contrib module. I added a new field to "user" entity. I need to hide this field from display in "manage display" I run this code $entity_view_display = \Drupal::...
Vanish's user avatar
  • 146
1 vote
1 answer
504 views

Can I use entityQuery() in a Drupal 10 site to query entities from a Drupal 7 database?

Can I use entityQuery() to query entities in a Drupal 7 table? I know it's possible to change the active database and then use a dynamic query to access the database, but can I do that also with ...
arnoldbird's user avatar
  • 1,267
0 votes
1 answer
160 views

Custom field type that has an array property won't save unless serialized, otherwise get "This value should be of the correct primitive type" error

I have a custom field type with two properties I am storing on it. One stores a string. The other I want to store an array. The array should be serialized in the field value table of the database, but ...
Kevin's user avatar
  • 27.9k

1
2 3 4 5
175