I need to pull the nid immediately after it is created using entity_metadata_wrapper as a creation method.  Here is a brief example:  $values = array(   'type' =&gt; 'content_type',   'uid' =&gt; $user-&gt;uid,   'status' =&gt; 1,   'comment' =&gt; 1,   'promote' =&gt; 0, );  $entity = entity_create('node', $values); $wrapper = entity_metadata_wrapper('node', $entity); $wrapper-&gt;title-&gt;set('title'); $wrapper-&gt;save(true); entity_save('node', $entity);   // From this, where can I get a NID value for the node that was just created?
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?
121478
I have a field within the user's profile set with their payroll. What I'm trying to achieve within my module is find the uid, based on the value of a payroll field.  I've tried a few things, but I can't get it to work. What I'm currently trying is this, but it returns unknown field of user  $query = new EntityFieldQuery();  $query-&gt;entityCondition('entity_type', 'user')   -&gt;fieldCondition('user', 'field_user_payroll', $payroll, '=');  $result = $query-&gt;execute(); $account = user_load($result);  $wrapper = entity_metadata_wrapper('user', $account); $mimemail = $wrapper-&gt;mimemail-&gt;raw();  watchdog('Photo Import', "Mimemail: %mimemail",    array('%mimemail' =&gt; $mimemail), WATCHDOG_INFO);   Any help would be really appreciated. It's driving me crazy!
3170
What is the best way to get IDENTITY of inserted row?  I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY but don't understand the pros and cons attached to each.  Can someone please explain the differences and when I should be using each?
112434
I'm trying to do some field level data analysis and it would be helpful to be able to pull out the CreatedDate and CreatedBy (Name) for each Custom Field (not individual records) on both Standard and Custom Objects.   I've experimented a bit with the Tooling API to retrieve this but wondering if there's an easier way.
120775
I have the following code and while get_the_ID() works, $post->ID does not, why?      $the_query = new WP_Query( array(         'post_type' =&gt; 'custompost',     ) );      while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post();         echo $post-&gt;ID;     endwhile;
30396
I'm programmatically creating a user with the following code.  $newUser = array(   'name' =&gt; $mail,    'pass' =&gt; 'password',  // note: do not md5 the password   'mail' =&gt; $mail,    'status' =&gt; 1,    'init' =&gt; $mail,   'roles' =&gt; array(5) ); $user = user_save(null, $newUser);   I have got a role with the role ID equal to 5; when I create the user, in the table "users_roles" there is only a row with the value 0 for the role ID, but if I print the user object with var_dump(), it looks like the roles are created.  What am I doing wrong?
24492
In a preprocess function I want to access the destination node id via the  I cannot find any method that will return the node id for me but I can clearly see that it holds the node id. (see attached)  Any idea how I can get the node id without going the long way of generating it from the URL path?
82816
I want to programmatically create a custom content (custom content created via the admin UI). Before the creation, I want to check the types of fields of my custom content.  My custom content contains a field "body" (type text), a field "description" (type text), an int field (type int), an attached file field (type fid ?).  I tested several ways; this is my last try.  // I get the entity object "my_custom_content" $entity_object = NodeType::load("my_custom_content"); dpm($entity_object); //Work perfectly   $test = \Drupal::getContainer()-&gt;get("entity_field.manager")-&gt;getFieldDefinitions("my_custom_content",$entity_object-&gt;bundle())   The code returns an error:     The my_custom_content entity type does not exist.   With this $entity_object, how can I get the list of the fields of my custom content?  I see the EntityFieldManager class, the FieldItemList class, but I still do not understand how to play with Drupal 8.
78056
I am using Salesforce's REST API to (1) retrieve a list of object IDs according to a query, then (2) retrieve the records that correlate to those IDs.  I am familiar with the Salesforce composite documentation .    My request looks like this:  POST: /services/data/v48.0/composite  {     "allOrNone":false,     "compositeRequest": [ {         "method":"GET",         "url": "/services/data/v48.0/query?q=SELECT+Id+FROM+My_Entity+WHERE+(CreatedById+!=+'asdfghjkl')",         "referenceId": "myEntity"         },{         "method":"GET",         "url": "/services/data/v48.0/composite/sobjects/My_Entity?ids=@{myEntity.records[0].Id}",         "referenceId":"myObject"     }] }   My response:  {     "compositeResponse" : [ {         "body" : {             "totalSize" : 21,             "done" : true,             "records" : [ {                 "attributes" : {                     "type" : "My_Entity",                     "url" : "/services/data/v48.0/sobjects/My_Entity/a0D6g000xxxxxxx"                 },                 "Id" : "a0D6g000xxxxxxx"                 }, {*record2*}, {*etc*}             ]},             "httpHeaders" : { },             "httpStatusCode" : 200,             "referenceId" : "myEntity"         }, {         "body" : [ {         "errorCode" : "PROCESSING_HALTED",         "message" : "'myEntity.records' references an invalid Datatype. Only Strings and primitive data types are allowed to be referenced from previous operations."         } ],         "httpHeaders" : { },         "httpStatusCode" : 400,         "referenceId" : "myObject"     } ] }   The first subrequest (the query) executes without errors.  My problem is the second subrequest.  I understand from  that I can refer to the ID of a single item (e.g. myEntity.records[0].Id).  Question: How do I use all items from myEntity.records in the second subrequest?
66704
Example: I want to get all tag names that are inside field_tags of node 5.  I can get the target_id with $node->field_tags->;     But the problem is, I don't know what entity the target_id value belongs to. Could be a node id, term id, user id. Without that info, I am not able to use the target_id to get the name of the tag.   How can I get all the names of an entity reference field?
51103
I am populating a junction object on from Events and want to capture info from the Event but getting the Account from Account field pulls null. Same who the name via the Who. But if I query the Event record, the AccountId field is populated. And of course, the code compiles properly. Can someone explain how to grab this related info?  trigger TripMeetingFromMeeting on Event (after insert, after update) {      Set&lt;id&gt;EventId = new Set &lt;ID&gt;();     List &lt;Trip_Meeting__c&gt; TMS = new List &lt;trip_meeting__c&gt;();      for (Event E:trigger.new){         if (e.Business_Trip__c!=null){             TMS.add(new Trip_Meeting__c(Meeting__c =e.id, Business_trip__c=e.Business_Trip__c,                                         Meeting_Date__c=e.ActivityDate, Meeting_subject__c=e.Subject,                                        TripNameDELETE__c=e.Business_Trip__r.name,                                         mWhatID__c=e.Whatid,                                        Meeting_Company__c=e.Account.name,                                        Meeting_Name__c=e.Who.name)                                         );          }     }     system.debug('TMS!!!============================'+TMS);      Database.insert(tms, false);  }
40506
I am writing a function that adds an ID number to an array and puts the array in the usermeta. $_GET['auction'] is the post_id.  Below is the function:  $reminders = get_user_meta( $current_user-&gt;ID, "reminders" ); print_r( $reminders ); if( in_array( $_GET['auction'], $reminders ) ) {     echo "Failed: Auction already in list"; } else {     array_push( $reminders, intval( $_GET['auction'] ) );     if ( update_user_meta( $current_user-&gt;ID, "reminders", $reminders ) ) {         echo "Success";     } else {         echo "Failed: Could not update user meta";     } } print_r( $reminders );   Here is the output after adding one auction:  Array ( )  Success Array ( [0] =&gt; 7 )    Here is the output after adding two auctions:  Array ( [0] =&gt; Array ( [0] =&gt; 7 ) )  Success Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 )   And here is the output after adding three auctions:  Array ( [0] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) )  Success Array ( [0] =&gt; Array ( [0] =&gt; Array ( [0] =&gt; 7 ) [1] =&gt; 73 ) [1] =&gt; 0 )   Notice that adding a new element to the array using array_push works fine. But when the array is stored in the usermeta then retrieved again, the last element in the array has been put into an array of its own, creating an infinitely dimensional array. I'd prefer to keep this array one dimensional.  Is there a way I can run update_user_meta and get_user_meta without it changing the structure of my array?
90347
How do i dynamically assign a name to a php object?  for example how would i assign a object to a var that is the id of the db row that i am using to create objects.  for example   $&lt;idnum&gt;= new object();   where idnum is the id from my database.
1862
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] =&gt; Array         (             [und] =&gt; Array                 (                     [0] =&gt; Array                         (                             [value] =&gt; 6                         )                      [1] =&gt; Array                         (                             [value] =&gt; 7                         )                      [2] =&gt; Array                         (                             [value] =&gt; 8                         )                  )          )   What API function can I use to actually load the field data contained in the collection that has an entity_id of 6, 7, 8, etc?
64273
Currently trying to update a field every time a node is created or updated. However the value is not being populated within the node, do I have access to the node object with this particular hook? What could I be missing?    function vbtoken_node_update($node) {         entity_get_controller('node')-&gt;resetCache(array($node-&gt;nid));         $types = node_type_get_types(); //What are the current Node Content Types?       $yes = ($types['volunteer_project']-&gt;type);        if($node-&gt;type === $yes){           $hash = md5($node-&gt;title . $node-&gt;nid . $node-&gt;nid);         $hashed = substr($hash, 0, 6);         $node = node_load($node-&gt;nid);         $node-&gt;tcode[$node-&gt;language][0]['value'] = $hashed;         node_save($node);          watchdog('vbtoken', 'Added a new Token code to %nid', array('%nid' =&gt; $node-&gt;nid));          }         else          {           dpm('not working dude');         }      }
40955
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 I'm thinking is to create a contact form entity and give it to the entityFormBuilder-&gt;getForm($contactFormEntity)  My current code is:  &lt;?php   /**  * @file  * Contains Drupal\pid_contactform_block\Plugin\Block\TellUsYourStoryBlock  */  namespace Drupal\pid_contactform_block\Plugin\Block;  use Drupal\Core\Block\BlockBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface;  /**  * Class TellUsYourStoryBlock  * @package Drupal\pid_contactform_block\Plugin\Block  * @Block(  *     id = "tell_us_your_story_block_id",  *     admin_label = "Tell us your story block",  *     module = "pid_contactform_block"  * )  */ class TellUsYourStoryBlock extends BlockBase implements ContainerFactoryPluginInterface {     protected $entityFormBuilder;  public function __construct(array $configuration, $plugin_id, $plugin_definition, $entityFormBuilder) {     parent::__construct($configuration, $plugin_id, $plugin_definition);     $this-&gt;entityFormBuilder = $entityFormBuilder; } /**  * Builds and returns the renderable array for this block plugin.  *  * If a block should not be rendered because it has no content, then this  * method must also ensure to return no content: it must then only return an  * empty array, or an empty array with #cache set (with cacheability metadata  * indicating the circumstances for it being empty).  *  * @return array  *   A renderable array representing the content of the block.  *  * @see \Drupal\block\BlockViewBuilder  */ public function build() {     return $this-&gt;entityFormBuilder-&gt;getForm();  }  /**  * Creates an instance of the plugin.  *  * @param \Symfony\Component\DependencyInjection\ContainerInterface $container  *   The container to pull out services used in the plugin.  * @param array $configuration  *   A configuration array containing information about the plugin instance.  * @param string $plugin_id  *   The plugin ID for the plugin instance.  * @param mixed $plugin_definition  *   The plugin implementation definition.  *  * @return static  *   Returns an instance of this plugin.  */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {     return new static(         $configuration,         $plugin_id,         $plugin_definition,         $container-&gt;get('entity.form_builder')     ); }   }  My question is basically:   Am i doing it the right way? How do I initialize the ContactForm entity correctly, if I am right, should I just import it or should I require it through a service or something? If I'm not right, do you have any idea how I should do it then?
73714
How do I use the Tooling API to create a new Apex Trigger (rather than update an existing one)?  According to the  I need to specify the ContentEntityId as an existing Trigger Id. But in my case I don't have an Id because I've trying to create a new sObject.  If I omit the ContentEntityId I get an error back in the SaveResult:     Status Code: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY   Message: "insufficient access rights on cross-reference id"   The following is more or less a test case in C# that attempts to use the SOAP tooling API to create the new trigger.  SforceService toolingService = //... Get instance of the Tooling API  MetadataContainer container = new MetadataContainer(); container.Name = "Test" + DateTime.Now.Ticks;  SaveResult[] saveResult = toolingService.create(new sObject[] { container }); string metaDataContainerId = saveResult[0].id;  ApexTriggerMember apexTriggerMember = new ApexTriggerMember(); apexTriggerMember.MetadataContainerId = metaDataContainerId; apexTriggerMember.Body = "trigger TestOpportunityBeforeUpdate on Opportunity (before update) {\n//Horray\n}";     // Adding this will successfuly update the existing trigger //apexTriggerMember.ContentEntityId = "01q70000000GuzP";  SaveResult[] triggerSaveResults = toolingService.create(new sObject[] { apexTriggerMember }); Assert.AreEqual(1, triggerSaveResults.Length); SaveResult triggerSaveResult = triggerSaveResults[0]; if (!triggerSaveResult.success) {     Assert.Fail(triggerSaveResult.errors[0].message); } Assert.IsTrue(triggerSaveResult.success);  ContainerAsyncRequest containerRequest = new ContainerAsyncRequest(); containerRequest.MetadataContainerId = metaDataContainerId; containerRequest.IsCheckOnly = false;  SaveResult[] containerResults = toolingService.create(new sObject[] { containerRequest });