Similar to #2709425: Implement field_extra_fields() for hosting_site, _platform, and _server. but for hook_entity_property_info, it would be nice if we implemented this because then the Entity API would know about all our custom properties that we're adding to nodes, and then other modules could make use of them easily.

For example, I want to use SearchAPI to search for sites within the Aegir UI, but can't surface any useful fields to it because they're all unknown as far as Search API is concerned.

Patch to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven Jones created an issue. See original summary.

Steven Jones’s picture

Status: Active » Needs review
FileSize
2.83 KB

Patch attached for review (and also in dev/2730603-hook_entity_property_info).

Just has an implementation for the site nodes at the moment.

Steven Jones’s picture

Here's the patch for platforms (again, also in git).

Steven Jones’s picture

clemens.tolboom’s picture

I've merged the patches into one to not waste time next time :p

I only found the server part patch (sick!)

The repo could use #2741809: Clean up repo branching ;-)

clemens.tolboom’s picture

Issue summary: View changes
Status: Needs review » Needs work
FileSize
94.16 KB

@Steven Jones please describe your testing.

I cannot find the 'new' fields

- create a rule to see the fields
- create a view to see the fields

None succeeded.

Below my hosting_task code (no patch as I don't want to derail this issue)


/**
 * Implements hook_entity_property_info().
 */
function hosting_task_entity_property_info() {
  $info['node']['bundles']['task']['properties'] = array(
      // TODO this is not in hosting_task_schema(). BUG?
      'task_type' => array(
          'label' => t('Task type'),
          'type' => 'text',
      ),
      'task_status' => array(
          'label' => t('Task status'),
          'description' => t('The status of the task. E.g. @TODO, etc.'),
          'type' => 'integer',
          'options list' => '_hosting_task_status_codes_labels',
      ),
      // FIXME: how should we expand these arguments?
      'task_arguments' => array(
          'label' => t('Task arguments'),
          'description' => t('The argument for the given. E.g. @TODO, etc.'),
          'type' => 'text',
      ),

  );

  return $info;
}

/**
 * Task status codes to human-readable label map.
 */
function _hosting_status_status_codes_labels() {
  $labels = array();
  foreach (_hosting_server_status_codes() as $code => $info) {
    $labels[$code] = $info['label'];
  }
  return $labels;
}
Steven Jones’s picture

Thanks for testing!

I was using search API to do the 'testing'.

clemens.tolboom’s picture

I 'found' the 'bug' regarding my tasks fields not popping up.

- Entity has field X does not show the fields
- Set a data value (task:task-type) is available but is not writable

Not writable

tbc

clemens.tolboom’s picture

Status: Needs work » Needs review
FileSize
8.51 KB

This is now a blocker for #2603704: Add action to create a new task

I've added my task part. Not I use hosting_task_entity_property_info_alter

To fix for #2603704: Add action to create a new task and in general for using Rules setting values we need to add the setters classes too.

@Steven I guess we need to use hook_entity_property_info_alter. What do you think?

clemens.tolboom’s picture

I puzzled a little more for using rules too.

To fix the setter for task_type adding a setter callback unblocks mentioned error in #8.

task_status needs some input (what are the integer values and their meaning?)

task_arguments seems to need the type struct but https://www.drupal.org/node/905580 states

This as well as any else not known type may be used for supporting arbitrary data structures. For that additional metadata has to be specified with the 'property info' key.

Note I use hook_entity_property_info_alter

Lastly I still cannot get the value for task_type in a rules condition.

@@ -1776,8 +1776,9 @@ function hosting_task_entity_property_info_alter(&$info) {
   $task_properties['task_type'] = array(
     'label' => t("Task type"),
     'description' => t("The type the task node uses."),
-    'type' => 'string',
-    //    'getter callback' => '_aegir_rules_task_node_get_properties',
+    'type' => 'text',
+    'getter callback' => 'entity_property_verbatim_get',
+    'setter callback' => 'entity_property_verbatim_set',
   );
 
   $task_properties['task_status'] = array(
@@ -1785,13 +1786,17 @@ function hosting_task_entity_property_info_alter(&$info) {
     'description' => t('The status of the task. E.g. @TODO, etc.'),
     'type' => 'integer',
     'options list' => '_hosting_task_status_codes_labels',
+    'setter callback' => 'entity_property_verbatim_set',
   );
 
   // FIXME: how should we expand these arguments?
   $task_properties['task_arguments'] = array(
     'label' => t('Task arguments'),
     'description' => t('The argument for the given. E.g. @TODO, etc.'),
-    'type' => 'text',
+    // FIXME list<text> is insufficient, list<struct> maybe the solution
+    // see ie commerce/modules/price/commerce_price.module commerce_price_field_data_property_info
+    'type' => 'list<struct>',
+    'setter callback' => 'entity_property_verbatim_set',
   );
 }
clemens.tolboom’s picture

So now I managed to generate a task through rules.

clemens.tolboom’s picture

clemens.tolboom’s picture

helmo’s picture

To test I created a rules component that creates a flush cache task.

{ "rules_flush_cache" : {
    "LABEL" : "Flush cache",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "TAGS" : [ "hosting task" ],
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "trigger_task" : { "label" : "Triggering task", "type" : "node" } },
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "trigger-task" ], "type" : "node" } },
      { "entity_is_of_bundle" : {
          "entity" : [ "trigger-task" ],
          "type" : "node",
          "bundle" : { "value" : { "task" : "task" } }
        }
      }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "task",
            "param_title" : "[trigger-task:title]",
            "param_author" : [ "trigger-task:author" ]
          },
          "PROVIDE" : { "entity_created" : { "new_task" : "New task" } }
        }
      },
      { "data_set" : { "data" : [ "new-task:rid" ], "value" : [ "trigger-task:rid" ] } },
      { "data_set" : { "data" : [ "new-task:task-status" ], "value" : "0" } },
      { "data_set" : { "data" : [ "new-task:task-type" ], "value" : "flush_cache" } },
      { "entity_save" : { "data" : [ "new-task" ], "immediate" : "1" } }
    ]
  }
}

This seems to work.

I should probably create an issue in the https://www.drupal.org/project/aegir_rules queue to start adding these there.

clemens.tolboom’s picture

@helmo guess we can move our rules examples over to issue #2603704: Add action to create a new task

Jon Pugh’s picture

Status: Needs review » Needs work

This looks good, but I haven't tested it out.

Ideally we finish the hosting task arguments before committing, but what if we just remove the hosting task arguments until it's ready?

If we finish or remove the hosting task argument, and someone else runs a decent test on it, we can mark it RTBC.

Great work!

Jon Pugh’s picture

Please leave the code, just comment it out. That way who ever picks it up from there doesn't have to start over.

Also, please change FIXME to @TODO.

Thanks!
Jon

helmo’s picture

Status: Needs work » Fixed

I've committed this with the 'FIXME' part disabled.

Lets continue in #2758635: Add task node metadata for arguments

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.