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
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 ...
4
votes
4answers
693 views

Should I change multiple text fields values via MySQL or is there any other preferable way?

The site has a content type and this content type has two fields: Text Field Term Reference Field There are thousands of nodes on this content type and I want to change some values (find/replace). ...
4
votes
1answer
198 views

How do I add a view mode to a simple custom entity?

I have created a super-simple drupal 8 custom entity. We now need a custom view mode for this entity. What do I need to add to my definition to make my entity appear as an option on the 'Add View ...
4
votes
7answers
9k views

Rename “-none-” option for select list field type

I have several list fields, one of which is a list (text) field. The default value for the form, where no value is stored if nothing is selected, is "-None-". Is there some way to alter this to say "-...
4
votes
2answers
3k views

How to refresh entity from entity_load(), reloading the entity as it is now?

If an entity has already been loaded, entity_load() retrieves it from memory rather than reloading it. Makes sense. But: what can you do when you need to reload an entity that has already been ...
4
votes
1answer
2k views

Why node custom fields weren't saved when adding node programmatically?

On node insert I want to save another node with data taken from first node into other Drupal database. The node in second site has 3 fields: title, image field, is_public. Both Drupal installation ...
3
votes
1answer
2k views

How to validate node field for minimum length for a custom content type?

I notice body has some preselectable minimum lengths. How do I do this for text fields? Also, how do I set a custom minimum length for node body of a content type?
3
votes
2answers
4k views

How to configure programmatically a unique constraint on several fields of a custom entity?

How could I configure a unique constraint on several fields of a custom entity I have already created with drupalconsole. The purpose is not allowing insert of two record of the same entity having ...
3
votes
1answer
7k views

How to programmatically set a custom field?

I am trying to programmatically change a custom field in a user object and I'm having very little success. I want to just use a function to set the field for the object, like field_get_items, except a ...
3
votes
2answers
2k views

How to change field cardinality per form either programatically or by rule?

I've a multipage form (where each page is determined by field group) where on the first page user type number of people in text field and on the second one I would like to show X number of field ...
3
votes
1answer
1k views

How do I get a field label in different languages?

In a module (not a template), I need the label of a specific field in multiple languages. $entity->getFieldDefinition('myField')->label() gives me the label in current/active language (let's ...
2
votes
1answer
576 views

Entity reference view depending on other field [closed]

I have a custom content type that contains an entity reference field (field_referencefield) and one more field as select box (field_triggerfield). The values of field_referencefield should depend on ...
2
votes
3answers
238 views

How to have a field that counts the nodes submitted by the current user?

My site with existing content needs a field that shows the number of nodes of a certain content type that have been created by the current user. I can't use Views because the field needs to be able ...
2
votes
1answer
1k views

Install a module that creates a content type with fileds via YAML

I am new to drupal 8, I have been using drupal 7 for quite some time and I used to write the code that creates content types and fields in hook_install / hook_update. Now I am creating a module that ...
1
vote
2answers
5k views

How can I access raw field values in a view template?

I am writing a template for a views field in Drupal 8. How can I access the raw values of a multi-value field in views? I tried this but it doesn't work. {% for i in 0.. row.field_color['#items']|...
0
votes
3answers
6k views

Extracting the values of Field Collection

I have created a foreach loop in my node template in Drupal 8 where values of the field collection are being printed as 1 and 2. Instead I want the content of the field collection which includes an ...
8
votes
6answers
5k views

Expose custom entity to views

I've created an entity in a Drupal 8 custom module. Right now it's just an entity with base fields. I want to expose these base fields to views. I have the entity appearing on the views wizard page, ...
8
votes
4answers
689 views

Is it acceptable to change the vid column of a term programmatically in the database?

I need to move some terms from one vocabulary to another by retaining all their data: translations, aliases, and node references. Is it acceptable to change its vid column value directly in the ...
7
votes
1answer
8k views

How do I programmatically render a custom entity? [closed]

I created a custom entity (submenu) in Drupal 8. I need to render this custom entity in my custom module. This is the code I am using. $entity_type = 'submenu'; $entity_id = '1'; // static for ...
6
votes
2answers
5k views

Context Filter with Path Alias in URL

Quick Summary: how do I pass a alias in a URL to a view's context filter, when that view is located somewhere in the site. I've read dozens of similar articles, but nothing that directly makes this ...
6
votes
4answers
10k views

How do you display the 'Title' field on display/page for custom content type?

I created a content type called 'News' and when creating a 'News' entity, I am able to enter a value for the 'Title' field. However, when I go to 'Manage display' for the content type, the 'Title' ...
6
votes
1answer
1k views

How to reference existing term if it exists or create new one if not exist via Inline Entity Form module?

I have a content type book and it has a taxonomy term reference field: author. I want to enter name and surname separately for each author on node add/edit page. Name and surname together will be the ...
6
votes
1answer
5k views

Preferred way of loading a specific entity revision

In drupal 7 you can do this to load an entity revision using entity_load($entity_type, $ids = FALSE, $conditions = array(), $reset = FALSE) like this: $old_revision = entity_load('node', array(), ...
6
votes
3answers
10k views

Get custom fields assigned to taxonomy

How to get custom fields assigned to taxonomy in Drupal 8. What I have done so far is: $contact_countries = \Drupal::service('entity_type.manager')->getStorage("taxonomy_term")->loadTree('...
6
votes
1answer
4k views

How do I programmatically get the field type of a specific field?

I'm able to get a list of the field types with the following code. $defs = \Drupal::service('plugin.manager.field.field_type')->getDefinitions(); I want to get the field type of a specific field. ...
5
votes
4answers
5k views

How to know add/edit page in hook_form_alter?

I want to know whether form is add/edit in hook_form_alter. In Drupal 7 we can get all these in hook_form_alter. I tried like this in D7: function MYMODULE_form_alter(&$form, &$form_state, $...
5
votes
1answer
3k views

remove Anonymous user from “Entity Reference” users list

in my case a project has a technical team, so project content type has a user reference field which is created by Entity reference module. but in node creation form, an "Anonymous" user is available ...
5
votes
5answers
2k views

CCK Field with two values?

Is there a way to have a CCK Field have two values for one input? For example, a field called 'Sodium' and two values, '190mg' and '8%'- first being the amount, second being % of daily value. If not,...
5
votes
3answers
3k views

Is there a Drupal 8 alternative for Inline Entity Form (to create an item while adding a reference)?

I have a Family content type and a Person content type. A Family has an Entity Reference field to one or more Persons. The normal workflow requires me to first create the Persons, then create the ...
4
votes
2answers
2k views

How do I in code add new field values to a D8 content entity?

How do I in code, create a new field value, add it to a content entity, and then have it saved to the DB? Field API is dead. Long live Entity Field API! clearly shows how to read values, but doesn't ...
4
votes
2answers
4k views

Including multiple authors in Authoring information for a Drupal 7 node

I have a CMS to which many people can possibly provide data. So, I would want to include all the users who have contributed the data for a node by adding new data or moderating existing data, because ...
3
votes
1answer
400 views

Register an anonymous user when entity form is submitted with rules

I have created an entityform called "Order Request". This form has fields for the user to enter their first name, last name, email address, and their order contents. I would like to register this ...
3
votes
2answers
747 views

How do I insert the image into article?

I am using field image to insert image into article. The image can't show in article body. How do I insert the image into article?
3
votes
2answers
5k views

How do I display a field twice in a node's display?

In my full node display I want to show the same field twice, in a different mode each time. Specifically, I have a collection of images, I want one up top and the rest below in my already existing ...
3
votes
1answer
5k views

Add CSS class to fields

I have the following snippet. function <themename>_preprocess_node(&$vars) { if ($vars['teaser'] && !$vars['is_front']) { $vars['theme_hook_suggestions'][] = 'node__teaser'; ...
3
votes
2answers
5k views

How to apply a Field Formatter to a node field programmatically?

I have the following code to get the value that is stored in a field $nid = 76; $node = \Drupal::service('entity.manager')->getStorage('node')->load($nid); foreach ($node->field_aaaa as $...
3
votes
2answers
1k views

How to change a fields label name based on another fields value?

I have a content type and it has two fields: Field One (select list) Field Two (text area) What I want to do is to change Field Two's label name based on Field One's value in node add/edit page and ...
3
votes
2answers
1k views

Where can I find complete documentation of hook_field_info?

When I looked into the API documentation page of hook_field_info, it seems to be quite complete. But I could not see the complete details of the return array ingredients. Why cannot I find the ...
3
votes
3answers
5k views

EntityFieldQuery fieldCondition

I have the following code: $query = new EntityFieldQuery(); $result = $query ->entityCondition('entity_type', 'field_collection_item', '=') ->propertyCondition('field_name', '...
3
votes
1answer
671 views

How to progragrammatically get NodeType translated value in D8?

Fetching node translation $node = Node::load($nid); $node->getTitle(); // returns title in en(default language). $translated_node = \Drupal::service('entity.repository')->...
3
votes
1answer
964 views

How can I save/load my Entity from a different database in Drupal 8?

For a custom Drupal 8 module I am integrating data from a separate database (other than the default drupal database) by defining a new Drupal entity in my module. How can I configure my Entity class (...
2
votes
1answer
803 views

What is the difference between getValue() and referencedEntities() to fetch paragraphs?

What is the difference between using getValue() and referencedEntities() in order to get the paragraph on a node? See example below. Both examples are used in a node template such as node--page--full....
2
votes
2answers
922 views

Show field twice in node page

I created a custom bundle (content type) and I've created fields One of those field is a file type field, is a video file, stored in the private storage. I installed the videojs module to allow to ...
2
votes
1answer
3k views

Views: custom field for sort criteria

My View has a " Global: Custom text"- Field that contains Integers (1,3, ..). The field is overwritten by a php-Template. I want to add this field to "Sort criteria", so the view can be sorted - but ...
2
votes
1answer
105 views

How do I make the output of field X look like Y?

I have a field of type X, and it's output is not quite the way I want to it to be. I would like it to look like Y instead. How can I do that?
2
votes
1answer
691 views

Referencing nodes reciprocally

I have a content type called Project which can relate to n projects of the same content type. This is done with a field called related projects using the D8 core Entity References. A possible ...
2
votes
2answers
2k views

How can we find the id of the parent form in preprocess_HOOK() or HOOK_alter() theme functions?

I'm working with an entity-creation form that needs some extensive theming. So far this has required me to alter template suggestions and create (twig) template variables for fieldsets. I've used ...
2
votes
4answers
1k views

The Field module shows an error when I call drupal_get_form()

I have a menu local task callback in hook_menu(): $items['leg/add'] = array( 'title' => t('Create a new leg'), 'page callback' => 'mymodule_leg_node_form', 'access arguments' => ...
2
votes
1answer
2k views

Improving performance with Field Collections?

I'm using using entity reference, field collection , and field collection table modules on a site that features "courses" and "lessons" as content types. A field collection with unlimited values is ...
1
vote
1answer
1k views

How to sort field_info_instances return value by field weight?

I'm using field_info_instances() to retrieve the information for all the fields used by a content type, for example calling it as field_info_instances('node','bundle_name'). In the returned array, the ...

1
3 4
5
6 7
19