Questions tagged [entities]
Nodes, comments, taxonomy terms, and users, in the terminology used since Drupal 7, are generally called "entities."
8,695
questions
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
737
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
113
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()
->...
0
votes
1
answer
162
views
Can I add fields to bundle classes?
The docs I've found so far tell how to add bundle-specific fields in either hook_entity_bundle_field_info() or in bundleFieldDefinitions() in my content entity class. While those work it seems ...
-2
votes
2
answers
53
views
not sure the properly way to call an entity
Hi sorry for the question but im new and im starting to undertand abou entities but is still hard for me. IM not sure about how to call the entities.
Here i didnt have a problem tu get the number.
$...
0
votes
1
answer
62
views
Error: on cron (field_purge_batch)
Seems that Drupal got issues removing deleted fields on cron (just a theory).
Got the following error message after cron ran. Anybody got an idea how to get rid of it?
Warning: foreach() argument must ...
1
vote
1
answer
130
views
Trying to implement bundle classes for a custom content type
I've got a custom content type (generated by drush) that extends ContentEntityBase and a bundle class (also generated by drush) that extends my content type. I've registered my bundle with ...
0
votes
0
answers
70
views
Why are facets not displayed on pages?
I have two entities: Entity Product and Entity Product Category. Entity Product has an entity reference field on the Entity Product Category.
Goal:
Display categories and their number on the right by ...
0
votes
1
answer
152
views
Can't uninstall fields that depend on a module incompatible with current version
I'm upgrading a site from Drupal 8 to 9. In its Drupal 8 version it used the field_collection module. There are some fields that still exist in some ghostly manner, that depend on the field_collection ...
0
votes
2
answers
163
views
Custom entity integration
I have created an entity, contactdata, and am trying to expose this entity to views. I have created my own views_data handler class, contactdataEntityViewsData, and have annotated my custom entity to ...
1
vote
1
answer
188
views
How to programmatically edit field settings of a content type
My ultimate goal is to use a drush command to change the allowed paragraphs in a paragraph entity reference field for various content types.
I'm able to load the field entity and see the settings I ...
3
votes
0
answers
103
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 ...
0
votes
1
answer
156
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?
0
votes
1
answer
46
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 ...
0
votes
1
answer
203
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 ...
2
votes
2
answers
377
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 ...
3
votes
1
answer
90
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)
-&...
1
vote
1
answer
45
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 ...
0
votes
1
answer
20
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 ...
0
votes
1
answer
30
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) {
$...
0
votes
0
answers
50
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 ...
0
votes
0
answers
105
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 ...
0
votes
2
answers
60
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 ...
0
votes
0
answers
36
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 ...
1
vote
1
answer
256
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
24
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('...
0
votes
0
answers
397
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 ...
0
votes
0
answers
28
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 ...
2
votes
0
answers
189
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
64
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
400
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(...
0
votes
0
answers
17
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 ...
1
vote
1
answer
50
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
267
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
0
answers
99
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 /...
1
vote
1
answer
123
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
38
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
489
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
40
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
51
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
151
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
81
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
122
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
195
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
364
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
551
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
114
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
68
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
115
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 ...