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
11
votes
4answers
16k views

Using Twig how can I get the summary of the body field to use in a template?

So I have a textarea with summary and I want to display the summary before the content. So if I just use {{ content.body }} the text is displayed without the summary. How can I get the summary ? {{ ...
10
votes
9answers
14k views

How to delete 1600 users and 2500 posts?

A couple years ago I configured a site with Drupal 6.9, and then I forgot about it. I have 160 pages of users that are all spammers and I need to delete all but 3. Doing this one page at a time is ...
9
votes
5answers
16k views

How to properly delete a field collection?

Drupal version: 7.21 Field collection module version: 7.x-1.0-beta5 Short explanation: I'm busy trying to import field collections programmatically but when deleting some of them there's always some ...
9
votes
1answer
2k views

Add field in hook_node_info();

Is it possible to add fields to a node type declared using hook_node_info? Do I have to add the fields separately? If so, what hook would I use for that?
8
votes
1answer
906 views

Why are values in Entites obtained directly and sometimes by using getters?

For example Drupal\Core\Entity\Entity::id() returns $this->id(or NULL) Drupal\Core\Entity\ContentEntityBase::id() returns $this->id->value Drupal\Core\Entity\ContentEntityBase::uuid() ...
7
votes
1answer
8k views

Entity metadata wrapper, get field collection in field collection

I want to get (and to set after) the value of a field collection in a field collection (multidimensional field content). This is my code : // The node is a custom content. // I get the list of ...
7
votes
2answers
7k views

How should I use hook_field_extra_fields()?

I just found out about hook_field_extra_fields(), but the documentation doesn't really tell me how to use it. Where is the extra-fields output generated? I tried hard to understand the Node and Poll ...
5
votes
2answers
4k views

How do I implement the equivalent of hook_url_inbound_alter()?

I'm working on a module which will resolve URLs to entities by altering inbound URLs so that if they contain an entity ID with following pattern "-{entity_id}" user will be redirected to correct URL. ...
3
votes
1answer
4k views

Using field values in page.html.twig

Using Drupal 8. I want to display the value of a field (field_date) at the top of my page, in the header, so I need to output it in page.html.twig. I'm having issue with this, though, which I think ...
2
votes
2answers
3k views

Email users on node creation based on taxonomy reference

I have 2 taxonomy vocabularies (town and topic) which are referenced on both a user and a node. When a node is created, I need to email all users who are referencing any of the terms referenced on the ...
13
votes
3answers
18k views

Alternative to Field Collection

Does anyone know an alternative to the module "field collection" ? While the concept of field collection is very good, I'm having trouble with the collaboration of other modules, like e.g. features ...
11
votes
1answer
6k views

How get empty record on date field with entityQuery?

I am on a custom entity with custom fields and i try to get all empty record on date field : Field was create with CCK, so the field storage has a table. $query = \Drupal::entityQuery('test_entity'...
11
votes
1answer
2k views

Does everything need a bundle?

I'm learning about the Entity API. I have a simple extra table that I'd like to "drupalize" so that I can use it in Views, for example. I've read quite a bit, watched a few videos, looked at quite a ...
11
votes
2answers
452 views

When should I use methods, get() and magic offset

There are three different ways to get an entity value, for example the node content type. $node->type->value $node->getType() $node->get('type') Which one should I use?
11
votes
6answers
27k views

Getting a field's value from an entity

What I have installed on my site is the Entity API and Entityform modules. The Entityform module allows me to create forms that any user can submit and the forms fields are available for me to use in ...
8
votes
1answer
1k views

How do I add a date field that can be filtered by a relative value?

If I create a view, I can add a filter that filters on a relative value on some built-in date field, such as Post date. For instance, the screenshot below shows a filter I've created that will show ...
8
votes
2answers
2k views

How do I rename a field?

With Drupal 7 we had the Field Rename module, but this has not yet been ported to Drupal. So what SQL magic is needed to rename a field in Drupal 8?
7
votes
2answers
9k views

How do I get a field label by the field name?

How do I get a field label by the field name in Drupal 7?
7
votes
7answers
4k views

What's the best practice to show a node's fields in different regions?

In D7 we used to create a view for nodes, with each field having an own display. Each display creates a block to place in any region of the site. But of course, Views are SQL-heavy. Now, Drupal 8 is ...
6
votes
4answers
3k views

How to add a database index to a base field

Goal: Add a database index to a 'created' field. Given: There is a custom entity with a base field created. The field is stored the entity table. Field source code of the created field: $fields['...
6
votes
1answer
1k views

How to add custom entities to group types?

I'd like to add my custom content entity to my group types, just like the module's "group node" plugin does already with nodes bundles. Has anyone done this? There does not seem to be much progress ...
6
votes
2answers
4k views

Rendering arbitrary field values without a parent entity in Drupal 8

I would like to expose to the user their choice of field formatters and the respective field formatter options. The selected formatter would then render an arbitrary array of items in the same format ...
6
votes
3answers
2k views

Restricting node reference values to owner

I have played with a bunch of modules (Node Reference Node Access, Views Field, View Reference) and can't seem to find one that does a very simple job; In one content type I want a field that provides ...
4
votes
2answers
3k views

Programmatically add a taxonomy term as entity reference in a custom entity

I'm really struggling to add a taxonomy_term as an entity reference to a custom entity I've created programmatically. Here is my configuration based on BaseFieldDefinition (the name of the vocabulary ...
4
votes
2answers
3k views

How can I print a field from a referenced entity in my theme?

I'm trying to print a field from an entity reference field - but I don't have a clue how to do it! A bit of background: I've got two content types - master and variation. Variation includes an ...
4
votes
2answers
2k views

Best way to change display for a field?

I have a node display that shows about 20 different fields. One of the fields is a list of years (multiple values). Instead of printing the list of years I would like to just show the first and last ...
4
votes
1answer
2k views

What is the difference between Referenced Entity and Referencing entity in views

I just wanted to know what is major difference between Entity Reference: Referenced Entity A bridge to the Content entity that is referenced via field_FIELD_NAME AND Entity Reference: Referencing ...
4
votes
3answers
6k views

select list in webform containing the list of node titles

how can we create a select list in webform containing the list of node titles of specific content type. I have a product content type through which I have added several product nodes. Now I want to ...
3
votes
2answers
2k views

Advantages of utilizing Entity Field query over views?

I've been reading a little about entity field queries. What are the advantages of using entity field queries (EFQ) over views? What are the largest pain points/disadvantages of using EFQ ?
3
votes
1answer
2k views

How to use inline_entity_form in Drupal 8?

I am building 2 custom Content entity types: one is a Node type representing a type of food, called "food". This food may have multiple varieties, which will differ with regards to specific details, ...
3
votes
5answers
8k views

How to properly delete fields, programmatically?

I have two content types on my site and I just deleted all the nodes using $node->delete(). For one of the content types, I noticed that the node body fields did not get deleted, nor did one of ...
2
votes
1answer
463 views

Is it proper to perform a db_update on an entity table?

I have a custom entity. During a save operation, under certain circumstances, I need to change the value of a specific field (not field API) of some other entities (of the same type). If I perform a ...
2
votes
3answers
10k views

How to print taxonomy terms field in node templates?

How can I display node taxonomy terms field in node templates of Drupal 8? We do this in Drupal 7 by add this code to node.tpl.php file: print render($content['field_tags']); I tried adding the ...
0
votes
1answer
5k views

How to use a field value in Template.php

Im sure this is an easy question, just not for me because of lack of experience with the Drupal preprocess hooks. I am removing the standard "Read More" links from my content. I want the ability to ...
19
votes
3answers
15k views

How to change a field value with a Rules Action?

I'm trying to set up a Rules Action that can change the value of a field. I created an Action Set with a data type of Node. When I go to create a Rules Action, I have access to every default Drupal ...
11
votes
6answers
19k views

How to display the summary (teaser) over the body in a full content view

I want to display a teaser on the top of each article under the title, as in following “full content” layout: Title Teaser (article summary) Image Body Moreover the teaser should have its own ...
9
votes
2answers
9k views

How remove whitespace on field in twig?

I try to print field value in a node--template.html.twig without whitespace. This field is a select in admin page. Location|Location Achat|Achat This is how my value is print : {{ content....
8
votes
3answers
5k views

Getting field labels from the $node variable

How can I get the labels of specific fields within a node, in Drupal 7? The field for which I am interested has the following structure: [field_text_question1] => Array( [und] => Array( ...
7
votes
2answers
3k views

How do i force a text format and hide the format selector in a formatted text field?

I Want to force a certain text format in a user profile text format field and hide the text format selector dropdown. How do i do it? This is for Drupal 8.
7
votes
5answers
17k views

Count number of values within a field that accepts unlimited values [closed]

I have an image field which can contain unlimited values. How can I display the number of image values contained within this field in views? I'm using Drupal 7.
7
votes
5answers
18k views

Twig get value of field in entity reference

i have a content type "actuality" with a reference to an other content type "event". In "event" i have a "field_date" which i want to print into my "actuality" node. What is the best way to do that ? ...
7
votes
2answers
9k views

How to add relationship in view for custom entity

I have an entity that references node and user via nid and uid fields. I have created an entity around my schema and would like to use it in views. I can create a view based on a new entity that ...
6
votes
3answers
7k views

How do I set access permissions per field?

What I need to do I have some user account fields that should be administrator-only (read/write/edit). For example, the IP address used to register. So, I want to restrict access to administrators. ...
6
votes
3answers
4k views

Force existing users to complete profile after adding required fields

I inherited a Drupal (D7) site with existing users. Now I want to add new fields to the user profile, but they will be required. New users will have to fill out these fields when registering. ...
6
votes
3answers
2k views

How to perform entity validation on code level?

I have an entity that has a field attached to it and the values that user types into the field has to be globally(website) unique(compared to other entities). I have added validation to the entity ...
6
votes
3answers
6k views

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class:...
5
votes
4answers
4k views

How to make EntityListBuilder sortable?

When defining custom content entities one can use EntityListBuilder to build a list of those entities for administrative purpose. By default such entities are ordered by ID, however it is possible to ...
5
votes
4answers
8k views

Is there a way to load the current entity object?

Is there a way, from anywhere in drupal, to get the current entity object? I'm using the hook hook_filter_FILTER_process() and I'd like to replace things in the $text with data from the entity, but it ...
5
votes
1answer
2k views

How to render Entity Reference fields in the current language

I am trying to render fields from an entity reference in a twig template but they are displaying in the default language instead of the selected one. My twig code: {% for location in node....
5
votes
3answers
6k views

default value for entity reference field

I have a form with an entity reference field and I need to add a default value. I've tried $form['field_op_product']['und'][0]['target_id']['#default_value'] = $product_node->nid; but, that doesn'...

1 2 3
4
5
19