How to alter a Rules Core Condition?

by Leiph   Last Updated January 09, 2018 11:07 AM

I need to use the core condition 'Entity has field' but without the selection list restriction.

Easiest way to implement this is to wipe out the two restrictions manually. But how do I do this in a more persistent way - surviving module updates?

Original code:

function rules_entity_condition_info() {
  return array(
 //other stuff
'entity_has_field' => array(
  'label' => t('Entity has field'),
  'parameter' => array(
    'entity' => array(
      'type' => 'entity',
      'label' => t('Entity'),
      'description' => t('Specifies the entity for which to evaluate the condition.'),
      'restriction' => 'selector',
    'field' => array(
      'type' => 'text',
      'label' => t('Field'),
      'description' => t('The name of the field to check for.'),
      'options list' => 'rules_condition_entity_has_field_options',
      'restriction' => 'input',
  'group' => t('Entities'),
  'base' => 'rules_condition_entity_has_field',
//more stuff
Tags : rules

Answers 1

Pretty much every info hook has an alter counterpart. hook_rules_condition_info is no exception so you should be able to do something like this:

function MYMODULE_rules_condition_info_alter(&$conditions) {
  // Change something
  $conditions['entity_has_field']['field']['restriction'] = '';
January 09, 2018 10:39 AM

Related Questions

Clone nodes and change fields with Rules and VBO

Updated May 20, 2015 20:03 PM