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
1answer
40 views

How do I validate an entity before programmatically saving it?

I have various functions/methods that programmatically create entities (nodes). I just noticed that invalid data has been getting stored in the db though these functions (invalid in that it doesn't ...
0
votes
2answers
97 views

Converting a Views SQL query with INNER JOIN to an EntityQuery

I'm trying to create a custom JSON:API resource that returns the entities that have been flagged by a user. (The Flag module does not offer a way to get this out of the box.) I used Views to build a ...
0
votes
0answers
59 views

Custom entities

I am a Drupal 7 avid user and I am just getting into Drupal 8 development for work. The project we are currently working on involves creating about 3 different custom entities (not nodes, users, etc). ...
1
vote
1answer
22 views

Adding the category for a custom entity reference field add other fields to the same category

I have a custom entity reference field working well, but once I added the category to it the other entity reference fields appeared in the same category. Here is my code: /** * Plugin implementation ...
1
vote
0answers
39 views

Field type where big data is not loaded into memory if not needed

Background Normally when an entity is loaded in D7, the 'field_attach_load' step will load all the data from fields into the entity object. The field_sql_storage_field_storage_load() loads the data ...
0
votes
2answers
29 views

Hide comment box from node for Anonymous users

I am trying to hide the comment box for anonymous users. Anonymous users should only be able to view the comments. How can I hide the comment form?
0
votes
1answer
28 views

How can I limit an entity reference selection to a specific field value on the reference

I have a content type Research which has a an entity reference type of People. The problem is that I don't want to show ALL people but only people which have a certain value under their field named ...
0
votes
1answer
21 views

How can I have a new dropdown for each entity reference added?

I have a content type with an entity reference to another content type that has over a hundred items. I want to use a dropdown menu to select the entity, since the user won't always know the titles of ...
0
votes
1answer
36 views

How to put view results in an entity reference field?

So the scenario is like this: I have to create a "node" which has an entity reference field which can hold multiple values. I am looking for a way to be able to select view results to be ...
0
votes
0answers
44 views

Placing a block on an entity

I am aiming to place a block on an entity. It seems like this should be simple as entity integration in D8 is well-developed and (in parts) user-friendly. I can get the view block working fine and can ...
0
votes
1answer
22 views

Unprocessable Entity: The following relationship fields were provided as attributes

I'm trying to set the value of a taxonomy term entity reference field with a POST operation in JSON:API. const data = { data: { type: 'node--page', attributes: { field_text: { ...
0
votes
0answers
10 views

How do I set a grouped exposed filter of boolean fields in a view?

I have a view with fields used as filters and exposed to user in a dropdown. They are "grouped" in the filter section. These fields are boolean. I can't get them to work together. It's ...
0
votes
1answer
31 views

Correct way to get field definitions for entity types

I'm still pretty new to D8 so I'm getting to grips with the new way it deals with fields and the OOP way of doing it etc. I've got a hook in my module which I'm trying to add a submit handler to ...
1
vote
1answer
53 views

add Bundle field to a custom entity

I am trying to add a new bundle field into my custom entity, I added the following code into the MyCustomEntity.php file, I uninstalled my module, so, I installed it again, the field is showing up on ...
0
votes
0answers
128 views

Is there a way to apply cached access results to listings?

Code that is put in either hook_entity_access or an access handler has no effect on listings such as views field displays and search. I am not sure if this is by design or due to an error from my side,...
0
votes
1answer
19 views

How to modify the subfields of a custom field in hook presave

I have a custom field in a custom module that consists of 4 varchar type values. Each of these subfields are called 'prefix', 'suffix', 'body' and 'header'. In the hook presave, I want to modify only ...
2
votes
1answer
55 views

Add a custom action on admin content page

I want to add a custom action to the dropdown on the admin content page (/admin/content) as shown in the screenshot below using Drupal 9. The views module is enabled so that form is part of the view. ...
0
votes
2answers
49 views

Add new field related with other (this field isentity reference) - Custom entity

Is it possible to add a new field related to the entity reference field? Let me explain, I have one field called "student_id" which is an entity reference type, so I need to assign one ...
0
votes
1answer
49 views

Entity Reference returns blank content

I thought that omitting code and being more graphic was going to improve the question, but that only made it score negative hehehe. So I'm going to put in some code to make it look clearer. Here is ...
0
votes
1answer
18 views

How to render full profile2?

I am tring to load a full profile2. I a trying the following code <?php $uid = user_load($node->uid); $profile2_p = profile2_load_by_user($uid, 'profile2_profile'); print render($profile2_p); ?&...
0
votes
0answers
15 views

Commerce Marketplace Missing Roles and Buttons

My Install Drupal 7.77 Drupal Commerce 7.x-1.15 Commerce Marketplace 7.x-1.0-beta4 (all dependent modules are enabled) I have reviewed: Documentation mentions a Marketplace Owner Role https://git....
0
votes
0answers
40 views

Store custom field with SQL transaction

I have a custom module that implements a custom field. In that custom field, I have an integer. This integer is optional. The user can insert anyone or leave it empty. If the field is empty, the next ...
0
votes
1answer
98 views

Changing entity base field settings

Changing entity base field settings I have a custom car entity with 8 base fields like the following: $fields['color'] = BaseFieldDefinition::create('list_string') ->setLabel(t('Color')) -...
0
votes
0answers
76 views

Custom field with a custom entity reference

I have a custom content type 'project' with a title 'project_no'. I am creating a custom field 'project_reference' to be used in other content types. It has few fields; one of them is an entity ...
0
votes
1answer
64 views

How to display configuration updates when deleting fields programatically

I am working on a module that adds it's needed fields automatically when you enable it's function in the UI for specific entity types. It also deletes it's needed fields when you disable it's ...
1
vote
0answers
40 views

How to update entity value programatically after submitting the form?

I try to update automatically entity title after form is sent. I tried that in form_alter, but everybody guided me to use entity presave. I cannot manage to save the updated title however (please see ...
1
vote
0answers
40 views

Assign a task to a user

I have a batch function that is called when the user has submitted the webform. Is there a function where I can assign the task to a specific user or role using a batch function? function ...
0
votes
0answers
30 views

How do entity reference fields that reference the same entity avoid an endless chain of references?

We are using an multi-valued entity reference that references entities from the same Entity type. For example We have a Product Variation Type with an entity reference field on it, which references ...
0
votes
0answers
30 views

Programmatically add multiple values to an entity reference field

I use the following code to load entities by their IDs. $themes = entity_load('theme',array(7,8,9)); $thid = array(); foreach ($themes as $theme) { $thid[] = $theme->id; } Next, I should add ...
0
votes
1answer
35 views

How do I check the image's view mode in the image.html.twig template?

I'd like to detect the custom view mode (Structure > Display Modes) selected for an media entity (image) and then be able to have html output based on the view mode. Specifically I have a custom ...
3
votes
1answer
245 views

How to use loadByProperties when one of the properties is an array?

I have this configuration entity and I want to load an entity using the properties label and subregions Lets say I want to load the entity if it has the label CU and the subregions CU-04. Note that ...
1
vote
1answer
73 views

How to filter paragraphs by the field name on parent using entityQuery?

I have a paragraph type my_paragraph which is attached to a node type my_content_type on multiple fields like field_a, field_b, field_c, field_d. I want to load only those attached to some specific ...
-1
votes
2answers
60 views

How to convert a file into File Entity

I need to use file_copy in a custom module in D8. The function file_copy requires the first parameter to be a File Entity. Here is what I have tried but it doesn't work and returns an error: TypeError:...
-2
votes
1answer
34 views

How to setup module: Referer to Entity Reference

i tried to use this in url: site.com/node/add/material/?field_material_category=6 content type 'material' has entity field 'field_material_category' number '6' is nid of node content type '...
0
votes
0answers
31 views

How to create a computed field for a price range?

I am creating a computed field price_range from a price field on a content type. I have used the following code. /** * Implements hook_entity_base_field_info(). * * Adds price range computed field ...
-2
votes
1answer
30 views

I would like to create a content type - a static page that can be updated and searched for - that contains multiple content types in a specific order

The "new content type" would consist of several other content types. 1) Company with multiple fields (text, URL etc.) 2) product class (label, text) 3) product class description (label, text)...
0
votes
2answers
76 views

Get parent entity in media preprocess hook [duplicate]

I am having a paragraph with a media entity ref field "field_paragraph_image_ref". I would need to modiy the media twig template depending on a field value of the parent, which is a ...
1
vote
1answer
53 views

Add a new column to the backend

I am trying to add a new column to a table and I added the column using hook_update_N(). function cca_update_8902(&$sandbox) { db_add_field('cca_findings', 'cca_topic_id', array( 'type' =>...
0
votes
1answer
50 views

Custom block disable caching?

I've created a custom module to show On This Days in a block but they are not changing each day until I flush the caches. I call the entity: public function build() { $query = \Drupal::entityQuery(...
0
votes
1answer
122 views

How can I create a custom field type for a select with multiple values?

I need a field type with 3 select in it. The field type is created and works like a charm but I'd like one of these select may have multiple values. What must I change? I add '#multiple' => TRUE, ...
0
votes
1answer
21 views

Import data using ECK and feeds module

Is it possible to import data from CSV file and insert all in two different entities for example I have created two different entities, cadidates and exams entities, once I import data to exam entity ...
2
votes
0answers
24 views

Do fields that are not displayed affect rendering performance?

This is a general question about how Drupal renders content. Say I have a content type with 20 fields, including some entity references, text fields, integers, and so on. When I have a lot of fields ...
4
votes
1answer
70 views

Force a single value base field to be in a separate table?

I have a custom entity type (eg: myentitytype), and I would like to add a new base field to it via hook_entity_base_field_info(). As I understand it, single value fields (with a cardinality of 1) will ...
-1
votes
1answer
53 views

How to let the user fill in the “Recipient” field of the contact form?

I created a new type of contact form. It is called "Invitation". The problem is that the recipient field does not appear and it is not editable. I want the user to fill in the recipient's ...
0
votes
1answer
37 views

Target EntityBrowser in custom validation constraint

Having a custom validation constraint on an entity reference field using entity browser as form widget, I am trying to get the field light up in the form on validation violation. This is not working ...
2
votes
2answers
122 views

Can I create non-default EntityReferenceSelection?

I have the following EntityReferenceSelection plugin: /** * Provides an entity reference selection for my_entity. * * @EntityReferenceSelection( * id = "extra:my_entity", * label = &...
2
votes
1answer
83 views

Reverse entity reference lookup

I have a data structure where content type research has an entity reference field scientists. The content type scientists does not have any research reference entity field though. I can get all ...
-1
votes
1answer
45 views

How do I display only products that do not exceed the end date?

I created in my product type, a "Date interval" field. I created a view that contains this field. With a start date and an end date. I want my view to show only products that are within the ...
0
votes
1answer
17 views

How can I send mail containing rendered entity from referenced field?

How do I code a function for sending mail containing a rendered entity that is referenced from a field? I have content type A that contains static information, and content type B that users create and ...
0
votes
1answer
34 views

hiding field -reference option limit

Helloo ! I am using the D7 reference option limit module. I have two fields "primary" and "secondary" and I managed to reduce the choices of secondary based on the value of primary ...