0

I have created a custom entity "Project" with this fields: id, name.

I have created a rule and added an action "create entity" and selected "Project".

I have added another action "Set a data value" and selected "name" of the newly created entity project and I had this message : "The selected data property doesn't support writing."

Here is the entity property info

 /**
 * Implements hook_entity_property_info().
 */
function project_entity_property_info() {

  $info = array();

  $info['project']['properties']['id'] = array(
    'label' => t('Project ID'),
    'description' => t('The ID of the project.'),
    'type' => 'integer',
    'schema field' => 'id',
  );

  $info['project']['properties']['name'] = array(
    'label' => t('Project name'),
    'description' => t('Name of the project.'),
    'type' => 'text',
    'schema field' => 'name',
  );
  $info['project']['properties']['description'] = array(
    'label' => t('Project description'),
    'description' => t('Description of the project.'),
    'type' => 'text',
    'schema field' => 'description',
  );
  $info['project']['properties']['deadline'] = array(
    'label' => t('Deadline'),
    'description' => t('Project deadline.'),
    'type' => 'date',
    'schema field' => 'deadline',
  );

  return $info;
}
4
  • What is the field type of "name"? – Djouuuuh Oct 17 '14 at 9:27
  • name's type varchar – sel_space Oct 17 '14 at 11:15
  • 1
    Can you edit your question to provide your implementation of hook_entity_property_info()? If you don't know what that means, that's the problem :) – Clive Oct 21 '14 at 9:19
  • You've added the wrong hook @sel_space, we need to see the hook I mentioned in the previous comment, not hook_entity_info – Clive Oct 21 '14 at 9:38
4
+50

In the provided hook, You need to add the setter callback.

So it will be like:

function project_entity_property_info() {
  // .... rest of code removed for brevity.    

  $info['project']['properties']['name'] = array(
    'label' => t('Project name'),
    'description' => t('Name of the project.'),
    'type' => 'text',
    'schema field' => 'name',
    'setter callback' => 'entity_property_verbatim_set', // -> this is it!
  );

Now rules knows how to set the value on entity.

More information about the hook_entity_property_info can be found here. If name requires a complex workflow to be set, you can write your own setter similar to entity_property_verbatim_set (for validating purposes, or ...).

If you are benefiting from the power of Entity API you may declare it in your EntityMetadataController class. There is a default class called EntityDefaultMetadataController you can extend it and introduce it as your entity type's metadata controller.

Another option is to use entityspice to declare your entity type which takes care of it all.

Not the answer you're looking for? Browse other questions tagged or ask your own question.