I'm using the Entity reference module and want to select all nodes that has no parent defined. I'm trying with:  $query = new EntityFieldQuery(); $children = $query     -&gt;entityCondition('entity_type', 'node')     -&gt;entityCondition('bundle', 'page')     -&gt;propertyCondition('status', 1)     -&gt;fieldCondition('field_parent', 'target_id', null, 'IS NULL')     -&gt;execute();   .. but that does not give anything as the field "field_parent" is missing and not set to NULL. If I use IS NOT NULL I get all nodes that has a parent.  How can I select all nodes that has no parent (or is missing the field "field_parent")?    Thanks to Clive I managed to solve this in the following way:  $query = new EntityFieldQuery(); $children = $query     -&gt;entityCondition('entity_type', 'node')     -&gt;entityCondition('bundle', 'page')     -&gt;propertyCondition('status', 1)     -&gt;addTag('filter_no_parent')     -&gt;execute();  /** * Implements hook_query_TAG_alter() */ function mymodule_query_filter_no_parent_alter(QueryAlterableInterface $query) {     $query-&gt;leftJoin('field_data_field_parent', 'p', 'node.nid = p.entity_id');     $query-&gt;isNull('p.field_parent_target_id'); }
74508
Is it possible to select all of the entities who's xyz field is empty?  I tried soemthing like this:  -&gt;fieldCondition('field_name', 'value', NULL, 'IS NOT NULL');   However, this doesn't seem to work.  Any ideas?
92730
I'm trying to use the FIELDS(ALL) function in my apex test class, in order to prevent this kind of error  SObject row was retrieved via SOQL without querying the requested fields...  But I can't save class with such query, because of this error:         The SOQL FIELDS function is not supported with an unbounded set of fields in this API.   Api version on test class 51 When I try to use the same query by dev console, it works fine.  Any thoughts?
117690
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 is "specialite":  $fields['speciality_field'] = BaseFieldDefinition::create('entity_reference')   -&gt;setLabel(t('speciality'))   -&gt;setRevisionable(TRUE)   -&gt;setSetting('target_type', 'taxonomy_term')   &gt;setSetting('handler_settings', ['target_bundles' =&gt; ['specialite' =&gt; 'specialite']])   -&gt;setSetting('handler', 'default')   -&gt;setTranslatable(TRUE)   -&gt;setDisplayOptions('view', array(     'label' =&gt; 'hidden',     'type' =&gt; 'author',     'weight' =&gt; 0,   ))   -&gt;setDisplayOptions('form', array(     'type' =&gt; 'entity_reference_autocomplete',     'weight' =&gt; 5,     'settings' =&gt; array(       'match_operator' =&gt; 'CONTAINS',       'size' =&gt; '10',       'autocomplete_type' =&gt; 'tags',       'placeholder' =&gt; '',     ),   ))   -&gt;setDisplayConfigurable('form', TRUE)   -&gt;setDisplayConfigurable('view', TRUE);   This piece of code doesn't work, would you please help to find what I am missing, or redirect me to a good documentation explaining different values for handler_settings  Thank you so much.
94007
I would like to get all nodes that are of my_custom_type type in Drupal 8.  I know I can get all the nodes (of any type) with  and the list of all types by \Drupal\node\Entity\NodeType::loadMultiple().   But how to get only the nodes of given node type?  I really don't want to use specialized module for it (if it's possible), just keep it as simple as possible. I will use the solution in my custom module.  And loading all the nodes with \Drupal\node\Entity\Node::loadMultiple() and then check their type in foreach would hit the performance too much.
97438
My "Article" nodes have a "domain" field that links to a taxonomy term. My "Article" nodes also have a repeatable "entity reference" field "more like this" that links to other "article" nodes.  How can i restrict the list in the "more like this" field to show only the nodes that have the same "taxonomy term" that the node i am currently editing ?  Thanks a lot !
110197
I have a child form and I want to get the total of the child forms to update the parent with the sum total. I am struggling with the CAML query to get the total back. The below returns zero records at present because (i suspect) the query isn't quite right.          var query = '&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name="Engagement" /&gt;&lt;Value Type="Lookup"&gt;';             query += ParentEngagementID + ";#" + ParentEngagementText + "&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;";           console.log("Query is " + query);         //Checked in chrome this is: Query is &lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name="Engagement"&gt;&lt;/FieldRef&gt;&lt;Value Type="Lookup"&gt;106;#ABC Ltd - 31/03/2016 - Year End&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;          var viewFields = '&lt;ViewFields&gt;&lt;FieldRef Name="Budget_x0020_hours" /&gt;&lt;FieldRef Name="Actual_x0020_hours" /&gt;';             viewFields += '&lt;/ViewFields&gt;';          var NewBudgetTotal = 0.00;         var NewActualTotal = 0.00;         $().SPServices({             operation: "GetListItems",             async: false,             listName: "Work tracker - Products",             webURL: "/sites/UKIAsuDataAnalytics",             CAMLViewFields: viewFields,             CAMLQuery: query,             completefunc: function (xData, Status) {                 console.log("---------------------");                 console.log(status);                 console.log(xData.responseText);                 console.log("---------------------");                 $(xData.responseXML).SPFilterNode('z:row').each(function() {                     console.log('Processing list of returned CAML items');                     if($(this).attr("ows_Budget_x0020_hours")) {                         NewBudgetTotal += Number(parseFloat($(this).attr("ows_Budget_x0020_hours").split(";#")[0],2).toFixed(2));                     }                     if($(this).attr("ows_Actual_x0020_hours")) {                         NewActualTotal += Number(parseFloat($(this).attr("ows_Actual_x0020_hours").split(";#")[0],2).toFixed(2));                      }                 });             }         });   If I comment out the query the XML responses coming back are like the below, and you can see the Engagement field should match:      "&lt;z:row ows_Budget_x0020_hours='3.00000000000000' ows_Actual_x0020_hours='0' ows_MetaInfo='80;#' ows__ModerationStatus='0' ows__Level='1' ows_ID='80'      ows_UniqueId='80;#{E91295D7-EF93-4F11-B486-E00F6A6AB7DF}' ows_owshiddenversion='16' ows_FSObjType='80;#0' ows_Created='2016-07-13 10:17:15' ows_PermMask='0x7fffffffffffffff' ows_Modified='2016-08-26 18:58:30'      ows_Engagement='106;#ABC Ltd - 31/03/2016 - Year End' ows_FileRef='80;#sites/MySite/Lists/Work Tracker  Tools/80_.000' /&gt;"   I have tried all sorts of changes to the query for the content of "Engagement" but nothing helps. Any thoughts?  (Please don't blame me on design here - I am trying to patch up some Sharepoint "work" done by a colleague. I am certainly not the best person to do the patchup, as much as they weren't the person do to the work.)
70966
I am attempting to create a query with the objects Opportunity, Courses__c, and Prior_Qualifications__c.   Opportunity has parent-child relationships with both Courses__c and Prior_Qualifications__c. I want to be able to query only information with valid Courses__c records, so that I can disregard any results returned with valid Opportunity object information, but no Courses__c information. Is there a way to do this? Am I able to make a query such that:  Select Id,  (Select Course_Name__c from Courses__r) from Opportunity where Courses__r.Course_Name__c != ''   I know that this isn't a valid query... but can I do something like this?
32134
I'm using a SOQL to query the lookup relationships.  Primary Object: Opportunity  Secondary Object: Purchase__c.  From purchase__c we have a lookup to opportunity.  Field Name: Opportunity__c  Child Relationship Name: Purchases2  SOQL query:  for (Opportunity opp : [select Id, Name, (select id from Purchases2__r where Count__c&gt;0) from Opportunity where Id IN :oppIds])    whats wrong with my query? getting error below:     If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.
123090
In Drupal 8, I have a content type, that has an "entity_reference" field and I wish to access the referenced node's fields in twig template. the kint() output for the field is:   In this list I can't find the referenced node's field values. How can I (if at all possible) load the node or node fields/values in twig?  Best,  Alari
99190
I have a node object with image field named field_image. When I do  $node   -&gt;get('field_image')   -&gt;first()   -&gt;getValue()   I get array with some properties instead of entity object. The array looks like this:  'target_id' =&gt; string '8' (length=1) 'alt' =&gt; string '' (length=0) 'title' =&gt; string '' (length=0) 'width' =&gt; string '587' (length=3) 'height' =&gt; string '458' (length=3) '_loaded' =&gt; boolean true   '_accessCacheability' =&gt;      object(Drupal\Core\Cache\CacheableMetadata)[1092]       protected 'cacheContexts' =&gt;          array (size=0)           ...       protected 'cacheTags' =&gt;          array (size=0)           ...       protected 'cacheMaxAge' =&gt; int -1   Do I have to manullay load the file entity using target_id or there is a way to automatically get referenced entity object from instance of Drupal\image\Plugin\Field\FieldType\ImageItem?  Why the referenced entity is not accessible via getter? It could be lazy loaded if it's not available immediately.
72370
I want to update a node field's value when a node is updated.   Tried using the code mentioned here   use Drupal\node\Entity\Node;      function hello_world_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {        $check = \Drupal::routeMatch()-&gt;getParameter('node');        if ($check) {       $node = Node::load($check-&gt;nid-&gt;value);       $node-&gt;title-&gt;value = 'testing';     //set value for field       $node-&gt;save();       }     }   but it did not work. I get a 500 error after saving the node. I also tried taking out the if statement and specifying a node id $node = Node::load(1);  I also tried using   use Drupal\node\Entity\Node;   function hello_world_node_update(Drupal\node\NodeInterface $node) {  $node = Node::load(1); $node-&gt;set("title", 'New value'); // also tried $node-&gt;setTitle('The new Title'); $node-&gt;save();  }   but no luck either.   In addition, I tried using different hooks entity_presave, entity_update, node_update, but did not make any difference.
17698
There's an entity created by another module and I'd like to change some of the fields used on a listing page. Currently that page is using the entity's list builder class. Is there a way I can define a new list builder class, make my changes, and use that for this entity? I have tracked this down to where D8 get's entity definition and loads the list builder class from that. I can't find a way to alter the definitions or another way to inject a different class here.  In more specific terms, I have  and want to override the functionality around EckEntityListBuilder.
113594
I am working with a LINQ to SQL query and have run into an issue where I have 4 optional fields to filter the data result on.  By optional, I mean has the choice to enter a value or not.  Specifically, a few text boxes that could have a value or have an empty string and a few drop down lists that could have had a value selected or maybe not...  For example:      using (TagsModelDataContext db = new TagsModelDataContext())      {         var query = from tags in db.TagsHeaders                     where tags.CST.Equals(this.SelectedCust.CustCode.ToUpper())                      &amp;&amp; Utility.GetDate(DateTime.Parse(this.txtOrderDateFrom.Text)) &lt;= tags.ORDDTE                     &amp;&amp; Utility.GetDate(DateTime.Parse(this.txtOrderDateTo.Text)) &gt;= tags.ORDDTE                     select tags;         this.Results = query.ToADOTable(rec =&gt; new object[] { query });     }   Now I need to add the following fields/filters, but only if they are supplied by the user.   Product Number - Comes from another table that can be joined to TagsHeaders. PO Number - a field within the TagsHeaders table. Order Number - Similar to PO #, just different column. Product Status - If the user selected this from a drop down, need to apply selected value here.   The query I already have is working great, but to complete the function, need to be able to add these 4 other items in the where clause, just don't know how!
24554
I have a lookup relationship.  If I just do the following query it works fine:  Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; system.debug('c:' + c);   However with the following I get an error:  Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; String c2 = (String) r.getSobject('field__r').get('fieldchild__c');   Error message:     FATAL_ERROR System.NullPointerException: Attempt to de-reference a   null object
121031
I have a the following code:  // Create an Entity with wrapper   $node = entity_create('node', array('type' =&gt; 'person'));   $entity = entity_metadata_wrapper('node',  $node);    // Add a node title   $entity-&gt;title = $person['name'];    // Add the address information   $entity-&gt;field_person_address-&gt;thoroughfare = $person['address'];   $entity-&gt;field_person_address-&gt;locality = $person['city'];   $entity-&gt;field_person_address-&gt;administrative_area = $person['state'];   $entity-&gt;field_person_address-&gt;postal_code = $person['postalcode'];   $entity-&gt;field_person_address-&gt;country = $person['country'];    // Save the entity   $entity-&gt;save();   The data is saved in the DB perfeclty, but I need to get the entity ID of the new save node.   How do I do that?
41192
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 multiple nodes with same title.  Example:    This is a title (3) This is a title (2) This is a title (1)   I know the node ID is shown once a selection is made but I like to show it in the dropdown list in order to pick the right node quickly based on the node ID.
21469
I am studying the new database layer, and I am glad it is changed to an OOP layer. I need to implement a query with db_select(). I found I can add a WHERE statement with $query-&gt;condition(), but by default the conditions are AND'ed together.  How can I OR the conditions together?  $query=db_select('users','u')-&gt;fields('u',array('uid','title','created','uid')); $query-&gt;join('flag_content','fc' , 'u.uid = fc.content_id'); $query-&gt;condition('fc.fid', '5' , '='); $query-&gt;condition('fc.uid', $uid , '='); //…