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

How can I add workbench_access to a custom content entity?

I have a custom entity and want to use our current workbench_access scheme to it. I've google for a long time and can't find and example. This article says that workbench_access now supports multiple ...
1 vote
1 answer
42 views

Adding custom operations with hook_entity_operation()

I'm trying to add a custom entity operation to taxonomy terms of a specific vocabulary. I've found documentation on using hook_entity_operation() to add the operation, and that works, but I'm not sure ...
  • 744
0 votes
0 answers
23 views

Check if a value has changed [duplicate]

Is it possible to check within a constraint validation if a field value has changed? namespace Drupal\example\Plugin\Validation\Constraint; use Drupal\Core\Entity\EntityPublishedInterface; use ...
  • 625
2 votes
0 answers
31 views

How can I insert entity or view data into a form?

We would like to put our adoption contract online to reduce paperwork, recordkeeping, etc. In order to do so, we need to insert data from an existing entity (specifically the existing record for the ...
  • 21
1 vote
1 answer
22 views

How can we limit the end date selection to +90 days from now on core Date Range widget? [closed]

We're using Drupal 9's core Date Range module and need to limit the end date selection to no more than 90 days from today. I've searched far and wide and have not come up with a workable solution. ...
  • 1,103
0 votes
0 answers
73 views

Entity Print - Getting error while clicking on View PDF

I am using Entity Print module and I didn't change its default configs. I am using Dompdf library for generating PDF on node. I have enabled View PDF from Manage Display page. When I am clicking on ...
0 votes
0 answers
32 views

How to make an entity reference field only load a rendered entity, when clicking on it? (ajax load on click)

I want to mimic a zettelkasten system, by starting in a very simple way: An entity of type 'Note' includes a body and an entity reference field, that can reference another note (of the same entity ...
  • 578
0 votes
0 answers
41 views

How to limit the depth of embedded referenced entities

Using Drupal 9 or 10 Using a node type Page with one entity reference field, which is displayed as rendered entity, displaying the same Page content type. When viewing a page, how do I prevent the ...
  • 578
1 vote
0 answers
58 views

Why the form does not save data from the entity reference field?

I have a custom entity (with the name Entity Quote), from the add form of this entity I make a multistep form. In the custom entity Entity Quote, I added another custom entity (with the name Quote ...
  • 11
1 vote
1 answer
50 views

Can we export json schemas for type script usage?

We have a Drupal installation that acts as a backend and a front end that uses the HttpClientModule from Angular to query this data. Thanks to the typescript base, we can provide the functions of this ...
1 vote
1 answer
40 views

Is there a way to specify order in a search_api query manually given a set of node ids?

Using search_api I have an query with the following condition $query->condition('nid', [1,5,3,7,10], 'IN') I know I can sort by things like created date or title, but what if I knew the exact ...
  • 5,442
1 vote
0 answers
104 views

Add third party settings to a basefield definition

Is there a way to add third party settings when defining a basefield for a custom Content Entity? I am creating a new Entity type and want to keep the fields defined in code vs config as much as I can....
1 vote
1 answer
56 views

Correct schema for an Entity Reference in config settings

Background I am creating a schema for a custom module's config settings, which are saved from a simple settings form. It has some basic fields, such as a checkbox for a Boolean value for hiding some ...
  • 444
2 votes
0 answers
70 views

Why doesn't the entity access handler I wrote work when the entity is referenced?

I have set a handler for the access of my entity but when I reference it in another entity, the access is not checked. I want the reference and the entity to have the same access check. Any idea ? The ...
  • 21
1 vote
1 answer
95 views

Removing orphaned paragraph references from the user

Setup Drupal 9 site has Users and each user has a Paragraph that contains "Phone" data. User => Phone Paragraph connection is made via field $user->field_phone_para. Issue Somehow ...
  • 11
0 votes
1 answer
72 views

How do I get a DateTime from a timestamp field?

Suppose I have a timestamp base field on an entity type. I can do $entity->timefield->value and get the UNIX timestamp. But how do I get a DateTime object from this? I can see there is a ...
  • 816
0 votes
0 answers
37 views

How to add content to the form display of a content type from the GUI?

I am constructing a form for a new content type (entity) that implements a survey or questionnaire content type. This fields of this content type is added using the GUI. Each field consists of: A ...
0 votes
0 answers
24 views

Convert a custom entity from RevisionableContentEntityBase to EditorialContentEntityBase in an update hook?

I have a custom entity that was generated via the drush command. This created it as an extension of RevisionableContentEntityBase. I now have a need to add moderation states to the entity, but this is ...
0 votes
1 answer
104 views

Alter a route according the current user

I'm on D 9.4.x, trying to redirect the node.add route to a custom one, only when the current user has the right role\permission. So I don't think I can't work in the alterRoutes but I probably need to ...
  • 645
0 votes
0 answers
36 views

Get all url in visibility request_path in block_content if request_path['pages'] is /node/* or /news/*

I am creating a module for the administrator for Drupal 9. The purpose of this module is to show one of the block_content of a certain type in the table as a sample and create 2 links for it: for ...
0 votes
1 answer
99 views

How to render content entity as a token replacement?

I wonder what's the right way to render entity render array as a token replacement (value). I found 3 different ways in the contrib: using render method: https://git.drupalcode.org/project/aet/-/blob/...
0 votes
2 answers
93 views

How to add/install a new field to all bundles of certain entity types?

I need to add a new string field called instagram_owner to all bundles of nodes, media and file entities. If new bundles are created, I need the field on them too. This is what I have so far in my ...
0 votes
0 answers
14 views

How to disable or remove entity references with unlimited cardinality once one entity reference is chosen

I have a paragraphs field that references multiple entity references with unlimited cardinality. I want to disable or remove the other options once one of the entities is selected. The use case is ...
  • 111
0 votes
0 answers
61 views

How do I create bidirectional entity references? [duplicate]

How can I create a bidirectional link in a drupal entity? Let me explain, I have a content type called "software" in which I have a field (entity reference) called "article". When ...
0 votes
2 answers
334 views

How to display Media image with alt attribute in paragraph twig template

I'm trying to access alt attribute as in given example Get Media Image URL in Paragraphs Twig Template - Drupal 8 But there is an example how to access alt and title... That's easy, too. You should ...
0 votes
1 answer
61 views

How to return different entity reference fields from multiple bundles using the same name with JSON:API?

The Goal My site structure looks like this: Node content type A with entity reference field groupA pointing to a term with field groupAfield Node content type B with entity reference field groupB ...
0 votes
0 answers
325 views

PluginNotFoundException entity type does not exist when trying to uninstall any module

I've got this drupal website from a client that the another developer created, and they've made a mess with many things in this site. I'm having a problem where every time I try to uninstall a module, ...
0 votes
1 answer
50 views

How can I setRequired() for a BaseFieldDefinition per entity bundle?

I have an entity type animal with the following bundles: cow pig sparrow anteater In the Animal.php entity type definition, I create some base fields, one of which is an entity reference to Habitat. ...
0 votes
0 answers
26 views

Entity queue: Can I use entity browser for selection but keep a draggable table for re-ordering?

On a Drupal 9 site we have an entity queue. We would like to use a draggable table for re-ordering but when the editor clicks "Select entities" they would like to use a modal entity browser ...
  • 874
0 votes
1 answer
113 views

How to display entity reference field in User Profile Twig

I asked this over on the Drupal.org forum, but I thought I'd give it a try here too. I am using an taxonomy entity reference field to display author names on our site. I added a 'published_name' ...
  • 93
0 votes
1 answer
45 views

How to make a Form that retrieve an entity and check if the form input matches with any part of the entity

I'm using PHP 7.4 with Drupal 9.4.5. Hello, i'm new using Drupal programmatically and i'm trying to make a simple form that would allow me to insert an input and tell me if the inserted input exist, ...
0 votes
1 answer
85 views

Access Control for Entity List Builder

This maybe a very obvious and basic question, but I can't seem to find it asked anywhere else. I have a custom entity which has its list builder defined in the annotation and not is routing.yml. The ...
0 votes
0 answers
49 views

How to use setConstraints() for a custom constraint on BaseFieldDefinition?

I'm refactoring a node content type into a custom entity. On this entity, I add a datetime field: $fields['target_date'] = BaseFieldDefinition::create('datetime') ->setLabel(t('Target ...
0 votes
0 answers
37 views

Can't submit/process data from custom multi-value field type?

I'm trying to insert some data into a custom content entity I have made containing a custom (unlimited cardinality) field type I created that contains 5 values, a html text value, 2 entity references ...
0 votes
0 answers
76 views

What is the use case for "bundle fields" that are independent of an entity type's base fields?

So I can define a custom entity in code (quickstart: drush generate entity:content). I can then use BaseFieldDefinition to define base fields that will be shared by all entities of that type. However, ...
1 vote
1 answer
57 views

How to set a URL alias for a custom entity type generated with drush?

I created a custom content entity type with the command drush generate entity:content. Now I want to set a URL alias pattern at /admin/config/search/path/patterns, but my new custom content entity ...
1 vote
2 answers
111 views

Change the "add entity" page title on a custom content entity type using alterRoutes()?

I created a custom content entity type dog using drush generate entity:content. When I go to www.example.com/dog/add, the page title (the one in the <title> tag, not the <h1> tag) is "...
1 vote
2 answers
172 views

How to set the text format in BaseFieldDefinition::create()?

I'm creating a base field (text_long) on a content entity and I want to limit it the Plain text text format for all users at all times. I know I can use the Allowed Formats module to limit the options,...
1 vote
0 answers
26 views

List down only entities which share the same field value as another

I'd like to have a View of entities (e.g. nodes) that only "show duplicates", i.e. show entities that have a specific field having a value that's also used by two or more entities. To put it ...
  • 1,382
2 votes
0 answers
26 views

How to manage the order (or dependencies) of entity creation for a module that defines multiple new custom entities

I have a module I'm building that creates and uses multiple custom entities. For each entity I've created a relevant file, new_module/src/Entity/modulename_entity1.php, new_module/src/Entity/...
3 votes
1 answer
75 views

Entity level constraints - when and how should the validation be implemented?

I've created a custom constraint, and set it on an entity in the entity annotation: * @ContentEntityType( * id = "student", * label = @Translation("Student"), ... * ...
  • 16.4k
0 votes
0 answers
100 views

How to get the entity bundle class from $form_state->getFormObject->getEntity()?

In hook_form_alter(), I want to perform some operations using an entity bundle class. function mymodule_form_alter(array &$form, FormStateInterface $form_state, array $context): void { $...
0 votes
1 answer
43 views

How to re-save a referenced entity that is removed when saving the referencing entity?

I have added a field to the Tags vocabulary, Count. In my Tags taxonomy term entity bundle, I run a database query in preSave() to set the value of this field (how many nodes have an entity reference ...
1 vote
1 answer
80 views

How do I configure the route to the add form for a content type created as a bundle class?

I've got a custom content entity type, created for me by drush generate and I'm extending that using bundle classes. I've got a MyContentType class and a MyBundle class that extends it and provides ...
0 votes
0 answers
48 views

Computed FieldItemList with issues

For a headless Drupal backend, that is used mainly as a jsonApi endpoint, I added to nodes in general a field, that contains node translation paths (if created). With that I am able to show a menu ...
  • 687
1 vote
0 answers
48 views

Interfaces for entities? [closed]

The Drupal code standards explains that I should use interfaces. And I always did that. But I never understood why. because it allows more flexibility in extending code later Why does an interface ...
0 votes
0 answers
65 views

LogicException when trying to use load of entityTypeManager

I have an entity that describes a task. This task can have children that are assembled via a parent ID. I now try to get a list of all children following a parent. But the code at dpm is not even ...
0 votes
1 answer
78 views

How to reference a custom entity using BaseFieldDefinition::create('entity_reference')

Similar to how you can reference a user or a node, I would like to reference a custom entity: $fields['department_id'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('...
0 votes
1 answer
723 views

Call to a member function bundle() on null in Drupal\Core\Entity\Plugin\Condition\EntityBundle->evaluate()

I have a dev site built on Drupal 9.1.9 and now I'm trying to use the site in 9.3.9. Everything is fully functional on 9.1.9 but when I try to run the same site on 9.3.9 I get. I believe the error is ...
2 votes
1 answer
112 views

Why would loading nodes by UUID not work in a drush command?

I have a simple bit of test code to load nodes by UUID: $uuids = ['5e331255-adf6-423e-a355-dc02c621ffcd']; $nids = \Drupal::entityTypeManager()->getStorage('node') ->getQuery() ->...
  • 165k

1
2 3 4 5
174