Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [entities]

Nodes, comments, taxonomy terms, and users, using the terminology used since Drupal 7, are generally called "entities."

21
votes
5answers
5k views

Is displaying a working Field Widget Form on its own possible?

I'm interested in embedding a Field Widget Form out side the context of the whole node edit form. I have displayed full forms in the past using drupal_get_form but that doesn't seem to apply for ...
20
votes
3answers
41k views

How do I get the raw field value in a twig template?

myfield is a plain text field. {{ content.field_myfield }} renders the field with HTML markup and the field label. How do I render the raw value of the field? {{ content.field_myfield.value }} doesn'...
25
votes
5answers
19k views

Using OR with EntityFieldQuery

I have never had the need to do this before today, but it doesn't seem like you can make OR queries with EntityFieldQuery, since db_or is used for select queries. An example would get to all entities ...
40
votes
11answers
24k views

How do I remove a configuration object from the active configuration?

I'm writing a custom module for Drupal 8. It defines a field storage configuration object, in a file called modules/mymod/config/install/field.storage.bloom_stem.bs_twitter_ac.yml. The problem is ...
2
votes
1answer
864 views

Rule to store user's last post date and scheduled rule based 30 day reminder

In this scenario, user's can post 1 node of a specific content type every 30 days (interval changes depending on user role). We are using node_limit to accomplish this; it's doesn't play with rules. ...
45
votes
3answers
27k views

How to provide template for particular view mode?

I want to theme the search result view mode with a template. I had it in my head that naming a template file node--article--search-result.tpl.php would do the trick, but I'm obviously wrong about ...
71
votes
4answers
66k views

How do I load a field collection from a node?

I have a node that has a few field collections on it. When I look at node_load() output, I see: [field_rich_text_group] => Array ( [und] => Array ( ...
83
votes
7answers
15k views

When is it appropriate to create an Entity versus just adding a new content type?

What is the benefit to creating new entity types over just building a new content type? It seems a bit overkill to do all of the custom coding that is required to create a new entity when you have ...
55
votes
8answers
46k views

How to programmatically create Fields?

How can I approach implementing the following in Drupal 7? What I need to do is create a module which defines a new fieldable entity, called 'Company'. I have a list of, let's say, 20 fields that ...
21
votes
4answers
11k views

Relation vs. References vs. Entity Reference for managing node-reference-type relationships

References Entity Reference Relation It seems like there are several active modules that all have similar functionality. Can anyone offer any information as to which branch appears to be the most ...
8
votes
2answers
4k views

Show node IDs along with titles in Entity reference Autocomplete list

I'll like to add this functionality to the autocomplete widget in Entityreference field to show node ID next to the titles in the dropdown list. The reason behind the idea is to differentiate between ...
2
votes
1answer
4k views

Extracting URI value from Image in Views - Getting Index Error

I am trying to create a custom slideshow using Views. Please not that I am not using the Views Slideshow Module What I need to accomplish is to wrap the the relative URL for the images within a ...
3
votes
5answers
2k views

How to bulk update select list fields?

I have a content type and it has a select list field. There are two options Yes or No and this field is not a required field. The website has about 100,000 nodes and I want to bulk update all nodes ...
46
votes
7answers
38k views

How to change the length of field settings?

I have set once to a website a lenght limit to a field. And now the client wants to put more characters to that field. I cannot change the maximum size from Drupal because I get the following error ...
30
votes
5answers
27k views

Best practice for language key for “und” in hook_form_alter

I'm modifying in a form in my custom module. Code looks like: function my_module_form_alter(&$form, &$form_state, $form_id) { if ($form_id == "someID") { $form['...
16
votes
2answers
11k views

How to debug EntityMalformedException?

I've got fatal error EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7700 of .\includes\common.inc) when trying to access user/xyz. I tried to ...
24
votes
5answers
17k views

How to set value of file field with entity_metadata_wrapper

How do you set the value of a file field when using the entity_metadata_wrapper? I've tried doing this in code: $file = new stdClass(); $file->uid = 1; $file->uri = $file_path; $file->...
9
votes
4answers
16k views

Autofilling fields based on another field

I have a very complex situation where I need some advice. I have a content type my_content, which has a field collection field attached to it field_mycollection, which has an entity reference field ...
11
votes
5answers
39k views

How to print fields in node.tpl.php?

I need to print individual fields from the $content variable in node.tpl.php file in separate div tags. How do I do that and how do I find out what the field's names are?
3
votes
3answers
869 views

How to add up all items of a field collection field using Rules?

I have a field collection with unlimited values. Inside this field collection, there is a field called Price (field_price). I would like to addup all prices that are inside the field collection to ...
2
votes
2answers
2k views

How to fix entity property X doesn't support writing, when setting content type field values?

I've got a D7 content type with a few fields; nothing particularly special. I want to be able to programattically change the values of those fields from time to time, and so wrote a function like so: ...
55
votes
9answers
107k views

How do I access a field value for an entity (e.g. node) object?

node_load((int) $nid) loads a fully-populated node entity. $node->title->value gets the title, but how do I access field values in Drupal 8?
35
votes
5answers
16k views

Bulk field update?

I added a new (text) field to a Drupal 7 content type that already has many nodes. How can I fill the field with a default value for all these nodes?
19
votes
5answers
30k views

How to add additional display(view mode) for node?

I am creating a custom content type. By default, nodes support only two view modes (full and teaser): function mymodule_view($node, $view_mode) { if ($view_mode == 'full') { $node->...
38
votes
7answers
9k views

Is there a good way to inspect objects whose type is derived from the EntityDrupalWrapper class?

I'm sure this question applies to other complex object types, but EntityDrupalWrapper is the one I'm currently working with. This is the type of object returned by entity_metadata_wrapper() (and ...
10
votes
1answer
11k views

Send a form to twig template

How I can pass a form to twig template in Drupal 8? For example, I get this: a form: mymodule/src/Form/MyForm.php Then on my Controller: public function myController() { ?????? return [ ...
19
votes
4answers
8k views

EntityFieldQuery vs Db_select()

Why should I use EntityFieldQuery when I can do the same work with Db_select() to fetch the value. It would be better if someone can provide an example, not only a link.
13
votes
2answers
5k views

Override field template with custom module

Instead of adding tpl files (in this case, media-youtube-video.tpl.php) to the theme. How can I override field templates from a custom module? Including when the field is used in a View.
7
votes
1answer
3k views

How to implement a multi step approval with webforms/entityforms based on form components?

Is it possible to invoke multi-step submission workflow using either Webform or Entityform? Here is the scenario of workflows: An employee submits the form Superviser gets notification,...
7
votes
3answers
8k views

Listing entity fields

I wonder if there is a good, and easy way to get all fields of an entity. I have a taxonomy vocabulary. Its terms have a special field I want to make list in a select box in one of my modules, so ...
34
votes
9answers
5k views

What's a good balance between reusing fields versus creating new ones in the context of fields scalability?

I've read the following phrase on a website: Instead of adding new fields to a content type, adding existing fields is a better option to reduce the system’s complexity and to improve scalability. ...
13
votes
4answers
12k views

Get all fields defined in a bundle

to get all fields used in a content type, in Drupal 7 I use the following code. $fields = field_info_instances('node', 'article'); What is the equivalent for Drupal 8?
8
votes
2answers
10k views

How do programmatically create fields for content types, and ADD them to the the content type form

Say I have this field, "map_description". I know I would this function to define the field: $field = array( 'field_name' => 'map_description', 'cardinality' => 1, 'type' => 'text', ); ...
11
votes
1answer
4k views

Entity reference vs. taxonomy

Let's say I have a team, which has members. I have a content type for team and a content type for individual team members. Let's say there are also other relationships, for instance teams can belong ...
19
votes
7answers
12k views

fast saving single field value

I've got around 70k nodes of specified type on my site. I need to run an update on them. Some operations and setting one field to desired value. node_save is really slow and it causes crashes (too ...
4
votes
1answer
661 views

Can I delete leftover field_deleted_* tables?

I have a lot of field_deleted_* tables in the database and neither drush cr or running cron is removing them. Is it okay to just remove them from the database? How can I tell Drupal to remove them ...
5
votes
6answers
7k views

How to place Contact form in block?

I have to embed a contact form inside of a block, and I'm trying to use the entity.form_builder service, But I'm not sure which entity I should give it, I found Message and ContactForm entity, so what ...
3
votes
4answers
8k views

Views with Entity Reference

I'm not sure why this is difficult for me to get. It seems like it should be simple. I have a content type A and content type B. Content type B has an entity reference field to content type A. ...
6
votes
2answers
6k views

Add content type field programmatically

My module provides a configuration form which allows to select a content type and on submit 2 new fields will be added to the selected content types. I want to add these fields to the content types ...
1
vote
1answer
173 views

How to set the values of some fields depending on the value of a list box?

Remember the create password page of Drupal! while you are entering characters it tells you how string is your password! now I want to have something like this in a list box but a bit different. I ...
3
votes
1answer
844 views

How to iterate over all field collection items in an eMail body using Rules?

I'm trying to write a rule (using Rules) that will send an email to users of a role. Within the body of the email, I'd like to display the contents of a nested field collection. I've tried using what ...
1
vote
1answer
6k views

Field level permissions in Drupal 7

What is the best way to create a piece of content with multiple fields... allowing users to edit the content as a whole yet blocking the ability to edit. The setup I have is a piece of content that ...
20
votes
9answers
13k views

How to implement two way node references?

The node-reference module (a component of CCK) provides a great way to create a reference one node from another. What is the best way to expose a two-way relationship between the two? Example below: ...
24
votes
6answers
25k views

Programmatically attaching files

I have created the "Gallery" content type, and added two fields: "photo," and "document." I then used the following code for uploading a file in the "document" field: $file = file_save_upload('...
7
votes
4answers
5k views

How do I alter the entity type class?

In Drupal 8 you can load an entity with: $node = \Drupal::entityManager()->getStorage('node')->load(123); This looks for the entity definitions and finds that node is defined by Drupal\node\...
7
votes
2answers
11k views

Create Entity Programmatically in Drupal

I created an entity via Entity Construction Kit, Initially I wanted to use rules to create the new entity but the entity is fielded and the fields don't get exposed in rules (as of now, someone is ...
22
votes
2answers
4k views

Are there any benefits/caveats with using Entity Reference over Term Reference?

Pretty simple question really, but is there any benefit to using a core term reference field over an Entity Reference field? Obviously tagging is not really an option with Entity Reference, but I've ...
14
votes
1answer
5k views

What is the purpose of drush entity-updates?

After updating Drupal 8 modules, I have been warned on the Drupal 8 status page that: Entity/field definitions: The following changes were detected in the entity type and field definitions. ...
11
votes
4answers
10k views

Programmatically delete one entry from one field on one entity

What's the proper way to programmatically delete one specific field entry for a multi-entry field from one specific entity? (that's specific fields and specific entities, not field types or instances ...
11
votes
1answer
5k views

Why are field widgets not form elements?

Form elements are often separate from field widgets, yet they implement very similar functionality. Sometimes, their functionality also creep across the two apis, such as in this question: Is ...