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
52 views

How to properly extend Entity Query class?

I am working on some complex aggregate reporting that pulls from several sources (node type) and generates a report in a table display. There are about 10ish line items (could be more later) and ...
user avatar
  • 26.5k
0 votes
1 answer
26 views

Convert field from string_long to text_long

I need to convert a field on a paragraph from the string_long type to the text_long type. There is data in the field so I can't change it in the UI. How would I do this programmatically?
user avatar
  • 640
0 votes
1 answer
23 views

How do I override the template file of a view so that it no longer displays links in my view, but only the plain text?

How do I override the template file of a view so that it no longer displays links in my view, but only the plain text? This is a body field where the titles of the refenced entities are displayed as ...
user avatar
0 votes
1 answer
16 views

How to change a custom entity field type - with revisions

I have a custom content entity for which I needed to change the type of one of its fields. Following the example on Updating a base field type, I wrote code to update the base entity, which updated ...
user avatar
0 votes
0 answers
67 views

Fit locations does not work with GPX files

I installed the "Geolocation Field" module on Drupal 9. I created a "track" content type with a "Geolocation GPX File" field. I created a node with a GPX file loaded. ...
user avatar
  • 1
0 votes
0 answers
34 views

I cannot add fields to the User entity

After upgrading from Drupal 8 to Drupal 9.4, I get errors when I try to add a field to the User entity. There was a problem creating field daddd: Attempted to create an instance of field with name ...
user avatar
2 votes
2 answers
203 views

Is it a bad idea to have more than a custom entity defined in a module?

Fact #1 Drush module exposes two commands drush generate module-content-entity and drush generate module-configuration-entity, both generating new custom modules with entity classes defined. There is ...
user avatar
  • 121
3 votes
1 answer
27 views

Do I have to sanitize value parameters in a QueryInterface::condition statement?

Do I need to sanitize $userinput in this code, or is it done by Drupal? $nids = \Drupal::entityQuery('node') ->condition('type','my_node_type') ->condition('field_myfield', $userinput) -&...
user avatar
  • 59
1 vote
1 answer
24 views

Adding fields to custom content entity

I'm creating a new content entity called Points. My code already creates the table and its fields, but i cant see the fields in the entity form. I thought that fields in baseFieldDefinitions() should ...
user avatar
0 votes
1 answer
18 views

Drush emu throws error without hook_uninstall firing

I have a module that creates a custom entity. In the module.install file, in hook_uninstall, I remove any entity records. Running drush pmu results in an error because there are entity records. It ...
user avatar
0 votes
1 answer
23 views

How do I copy an address onto an entity?

This use case involves copying an address from CiviCRM into a field on a commerce product. Create a product Based on an event trigger protected function createProduct(EntityInterface $group) { $...
user avatar
  • 1,359
0 votes
0 answers
39 views

How to fix "Entity/Field Definitions" issue?

In Drupal 9 I deleted an image field with the machine name field_poi_image and I have a media field with the same machine name. Since then there is an error message in the dashboard. How can I correct ...
user avatar
0 votes
0 answers
30 views

Creating an instance of custom entity with entity reference field breaks entity collection page

I created two custom entities, entity_one and entity_two. entity_one has a entity reference field that allows you to select unlimited instances of entity_twos. The edit form for entity_one seems to ...
user avatar
  • 5,076
0 votes
2 answers
50 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 ...
user avatar
  • 14.8k
0 votes
0 answers
20 views

CSS & JS from programmatically rendered node

I have a problem and I can't solve it myself at the moment: In a view, I output some fields of a content type (through id in the context filter) via "REST export". With this view, I would ...
user avatar
1 vote
1 answer
59 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 ...
user avatar
  • 5,076
0 votes
1 answer
22 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('...
user avatar
0 votes
0 answers
69 views

How to render fields in nested paragraphs?

I'm trying to create a paragraph that will allow me to display several children's paragraph fields. I added the children-paragraph to the parent paragraph via Entity reference revisions. I created 3 ...
user avatar
  • 101
0 votes
0 answers
19 views

Filter or sort Multivalue Field of referenced Media items to their boolean field

I have a list of users who can add audios to their profiles via an multi-value entity reference field. The media/audio has an additional Boolean field to check if it's a primary or normal audio. In a ...
user avatar
1 vote
0 answers
52 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 ...
user avatar
0 votes
1 answer
55 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 ...
user avatar
0 votes
1 answer
39 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(...
user avatar
  • 605
0 votes
0 answers
14 views

Non-admins cannot see commerce entity bundle labels

I've got a drupal commerce site with two types of user roles -- admins and merchants. Merchants the ability to administer products for their stores, and so they have the Access the products overview ...
user avatar
  • 1,781
1 vote
1 answer
42 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
47 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 ...
user avatar
1 vote
0 answers
29 views

Access permissions with the Entity Print module

I installed the Entity Print on my site. It works perfectly when used from the administrator user, but it doesn't work with anonymous users. It gives the following error. Access denied on the url /...
user avatar
1 vote
1 answer
56 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', ...
user avatar
  • 26.5k
0 votes
1 answer
25 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 ...
user avatar
0 votes
1 answer
24 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 ...
user avatar
  • 490
0 votes
1 answer
42 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 ...
user avatar
  • 13
0 votes
2 answers
35 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 ...
user avatar
  • 15
0 votes
0 answers
48 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 ...
user avatar
0 votes
1 answer
40 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 ...
user avatar
0 votes
2 answers
59 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 / ...
user avatar
  • 653
1 vote
2 answers
30 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 ...
user avatar
-2 votes
2 answers
42 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. ...
user avatar
  • 49
2 votes
1 answer
74 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 '...
user avatar
  • 882
1 vote
1 answer
86 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 ...
user avatar
3 votes
2 answers
70 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 ...
user avatar
  • 1,939
0 votes
1 answer
34 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 ...
user avatar
0 votes
1 answer
27 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 ...
user avatar
  • 129
0 votes
0 answers
39 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 ...
user avatar
  • 247
0 votes
1 answer
112 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 ...
user avatar
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 ...
user avatar
0 votes
2 answers
36 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, ...
user avatar
  • 490
0 votes
2 answers
39 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 ...
user avatar
0 votes
0 answers
42 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?
user avatar
2 votes
1 answer
145 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 ($...
user avatar
1 vote
1 answer
42 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();...
user avatar
  • 640
-1 votes
1 answer
43 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: $...
user avatar
  • 943

1
2 3 4 5
174