I've tried several values for the URL, including path aliases, node/some_nid, and absolute paths. All result in the same error, shown below. The rest of the rule's actions fail because there is no result to act upon. If I fetch by nid, it works, however in this use case I do not know the nid, but I can construct the pattern for the path alias.

Warning: array_values() expects parameter 1 to be array, null given in rules_action_entity_query() (line 56 of /vol/www/humweb/sites/all/modules/rules/modules/entity.eval.inc).

Comments

jeff.k’s picture

I am experiencing the same issue when trying to load a user from their user url

realEuph’s picture

Title: Fetch entity by property URL doesn't work » Additional Info for Fetch by URL

This is the last key component in finishing off a project. I am researching the problem and reporting results here. I am trying to load a entity (node) by URL. I have used the full path (including http:) and the relative path. This is not yet a solution, but a report on what I have found.

I added print_r statements (using drupal_set_message) to dump out the structure of $return (defined in rules/modules/entity-eval.inc\\line 55) and $info (displayed just prior to entity/includes/entity.property.inc\\line 135).

rules_action_entity_query is what is called to process the fetch by URL property
rules_action_entity_query calls entity_property_query with same arguments

The dump of $return is empty/null (don't check)
The dump of $info is:

Array
(
    [label] => URL
    [description] => The URL of the node.
    [getter callback] => entity_metadata_entity_get_properties
    [type] => uri
    [computed] => 1
    [queryable] => 
)

If $info['query callback'] is not empty, then $info['query callback']($entity_type, $property, $value, $limit) is returned. As can be seen above, $info['query callback'] is empty.

I am still investigating why no query is in $info.

realEuph’s picture

Title: Additional Info for Fetch by URL » Fetch entity by property URL doesn't work

Sorry - restored old title

realEuph’s picture

After several hours working through 'entity_property_query' in entity/includes/entity.property.inc and 'rules_action_entity_query' in rules/modules/entity.eval.inc', I still don't know what is happening. I fell that this is more due to my lack of detailed knowledge of these modules than anything else.

For URL requests the structure returned by 'entity_get_all_property_info' does not contain information in the 'url' key that allows the function to return the desired information. In particular $info['queryable'] and $info['quert callback'] are not set. There is a comment about supporting the "deprecated query callback" that may not be supported from 'entity_get_all_property_info' because $info['getter callback'] is defined ('entity_metadata_entity_get_properties').

If I force setting $info['queryable'] and $info['quert callback'] (to 1 and 'entity_metadata_entity_get_properties', respectively), then the code fails when calling the callback because $property is not an array. If I make it one, the callback returns nothing.

When using the action "Fetch Entity by Author", significantly different results are present in the $properties object, leading to the return of the requested number of nids.

I suspect that there are two problems here:

  1. The Rules module does not know how to request a URL to nid query
  2. The Entity module does not know how to preform a URL to nid query - though this may reflect my (nearly non-existent) knowledge of the API
tigin öztürk’s picture

By using conditional rules, the property of entity can be fetch without using action "Fetch entity by property".
Add a conditional in the action part of rules. Than "If: Entity has field" is a good choice of fetching entity...

nicolas bouteille’s picture

Priority: Normal » Major
Issue summary: View changes

I can't seem to do it either.
I submit an entityform embeded in a node. I need to retrieve the node where the form has been submitted. I have printed site:current-page:path and site:current-page:url they are both referring to the correct node. But when I do entity fetch by property choosing Node and URL and select site:current-page:url, I get the exact same error message.

robdubparker’s picture

I ran into the same issue... I was trying to fetch an entity by url property, and got the same errors. As a workaround I added a custom module to handle the path to nid conversion, then used "fetch entity by id" option instead. This did the trick. Code I used in the custom module is below. Hope this helps.

/**
 * @file
 * A plugin for transforming data in rules.
 */

/**
 * Implements hook_rules_action_info().
 */
function cutter_helpers_rules_action_info() {
  $return = array(
    'pathtonid' => array(
      'label' => t('Convert path to nid'),
      'parameter' => array(
        'input_text' => array(
          'type' => 'text',
          'label' => t('Input text'),
        ),
      ),
      'provides' => array(
        'pathtonid' => array(
          'type' => 'integer',
          'label' => t('Node ID'),
        ),
      ),
      'group' => t('Data Transforms'),
      'base' => 'cutter_helpers_action_pathtonid',
    ),
  );
  return $return;
}

/**
 * Action: Add variable.
 * Gets nid from path alias.
 */
function cutter_helpers_action_pathtonid($input_text) {
  $path = drupal_get_normal_path($input_text);
  $parts = explode('/', $path);
  // nodes will always have 2 parts in url
  if (count($parts) == 2){
    if($parts[0] == 'node' && is_numeric($parts[1])){
      $input_text = $parts[1];
    }
  }
  return array('pathtonid' => $input_text);
}
Yuri’s picture

This should be included in Rules. There are many use cases such as forms and entities in panels that need the current entity ID.