Questions tagged [entities]
Nodes, comments, taxonomy terms, and users, in the terminology used since Drupal 7, are generally called "entities."
945
questions
21
votes
5
answers
6k
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 ...
27
votes
5
answers
21k
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 ...
2
votes
1
answer
1k
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.
...
46
votes
15
answers
45k
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 ...
14
votes
4
answers
19k
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 ...
49
votes
3
answers
30k
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 ...
80
votes
11
answers
228k
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?
78
votes
4
answers
74k
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
(
...
9
votes
2
answers
9k
views
Override theme template from module without implementing a theme
I have a project on D8 where I don't use any custom themes, I use default seven theme for everything because there is no need of any visual theming.
So My question: Is it possible to override theme ...
88
votes
7
answers
18k
views
When is it appropriate to create an entity instead of 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 ...
57
votes
9
answers
53k
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 ...
23
votes
3
answers
28k
views
Get all fields defined in a bundle
In Drupal 7, to get all fields used in a content type, I use the following code.
$fields = field_info_instances('node', 'article');
What is the equivalent for Drupal 8?
20
votes
4
answers
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 ...
19
votes
3
answers
16k
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 ...
9
votes
3
answers
8k
views
How do I load a form with a specific form display (form mode)?
On a custom page I'm trying to load an user edit form with a specific form display.
I'm able to load the form however I can't figure out how to load the form with the specific display.
This is what I ...
8
votes
3
answers
7k
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 ...
5
votes
1
answer
7k
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
5
answers
3k
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 ...
38
votes
7
answers
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 ...
32
votes
4
answers
57k
views
Programmatically update an entity reference field
I know I can update (or set a value for) an entity reference field in Drupal 7 with code similar to the following.
$node['field_code_used_by'][LANGUAGE_NONE][0]['target_id'] = $id;
I want to ...
30
votes
5
answers
28k
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['...
24
votes
5
answers
19k
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->...
11
votes
5
answers
40k
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?
10
votes
4
answers
20k
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 ...
9
votes
4
answers
36k
views
Get the value of a field from an entity reference
I have a content type (Actuality) with an entity reference field to another content type (Event). In the referenced content type, I have a field_date field I want to print in the node--actuality.html....
2
votes
2
answers
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:
...
2
votes
3
answers
1k
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 ...
50
votes
7
answers
45k
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 ...
36
votes
9
answers
6k
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.
...
35
votes
5
answers
18k
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?
20
votes
7
answers
15k
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 ...
18
votes
4
answers
10k
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.
14
votes
5
answers
10k
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\...
13
votes
2
answers
6k
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.
9
votes
1
answer
18k
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 [
...
8
votes
1
answer
1k
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 ...
8
votes
3
answers
9k
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 ...
7
votes
1
answer
4k
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,...
6
votes
1
answer
2k
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 ...
27
votes
1
answer
21k
views
How to create a view type of Entity reference display?
I have an entity which contains a field collection of entity references and can edit the entity references with the Entity selection mode is Simple (with optional filter by bundle), but only Entity ...
11
votes
1
answer
5k
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 ...
6
votes
7
answers
11k
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 ...
4
votes
4
answers
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. ...
3
votes
1
answer
1k
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
1
answer
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 ...
1
vote
1
answer
232
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 ...
0
votes
2
answers
85
views
Entity Reference widget selctor in view referring same reference
I searched for a solution but I didn't get it right.
Given my setup:
A content type Service, referring a content type Agency
A content type Agency
A content type Person, referring a content type ...
32
votes
4
answers
35k
views
How do I render nodes, now that node_view() has been deprecated?
In Drupal 7 I frequently use node_view() for rendering nodes (using view modes) in blocks or pages as follows:
$nids = array(123,456,789);
$nodes = node_load_multiple($nids);
foreach ($nodes as $node)...
25
votes
6
answers
27k
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('...
21
votes
5
answers
40k
views
Hide a field label
Is there a way to hide the field label when rendering a custom field in Drupal 7?
In my node template I have:
<?php print render($content['field_image']); ?>
Which gives me:
<div class="...