You are here

class EntityDefaultRulesController in Entity API 7

Default controller for generating Rules integration.

Hierarchy

Expanded class hierarchy of EntityDefaultRulesController

1 string reference to 'EntityDefaultRulesController'
entity_rules_event_info in ./entity.rules.inc
Implements hook_rules_event_info().

File

./entity.rules.inc, line 15
Provides Rules integration for entities provided via the CRUD API.

View source
class EntityDefaultRulesController {
  protected $type, $info;
  public function __construct($type) {
    $this->type = $type;
    $this->info = entity_get_info($type);
  }
  public function eventInfo() {
    $info = $this->info;
    $type = $this->type;
    $label = $info['label'];
    $defaults = array(
      'module' => isset($info['module']) ? $info['module'] : 'entity',
      'group' => $label,
      'access callback' => 'entity_rules_integration_event_access',
    );
    $items[$type . '_insert'] = $defaults + array(
      'label' => t('After saving a new @entity', array(
        '@entity' => drupal_strtolower($label),
      )),
      'variables' => entity_rules_events_variables($type, t('created @entity', array(
        '@entity' => drupal_strtolower($label),
      ))),
    );
    $items[$type . '_update'] = $defaults + array(
      'label' => t('After updating an existing @entity', array(
        '@entity' => drupal_strtolower($label),
      )),
      'variables' => entity_rules_events_variables($type, t('updated @entity', array(
        '@entity' => drupal_strtolower($label),
      )), TRUE),
    );
    $items[$type . '_presave'] = $defaults + array(
      'label' => t('Before saving a @entity', array(
        '@entity' => drupal_strtolower($label),
      )),
      'variables' => entity_rules_events_variables($type, t('saved @entity', array(
        '@entity' => drupal_strtolower($label),
      )), TRUE),
    );
    $items[$type . '_delete'] = $defaults + array(
      'label' => t('After deleting a @entity', array(
        '@entity' => drupal_strtolower($label),
      )),
      'variables' => entity_rules_events_variables($type, t('deleted @entity', array(
        '@entity' => drupal_strtolower($label),
      ))),
    );
    if (count($info['view modes'])) {
      $items[$type . '_view'] = $defaults + array(
        'label' => t('@entity is viewed', array(
          '@entity' => $label,
        )),
        'variables' => entity_rules_events_variables($type, t('viewed @entity', array(
          '@entity' => drupal_strtolower($label),
        ))) + array(
          'view_mode' => array(
            'type' => 'text',
            'label' => t('view mode'),
            'options list' => 'rules_get_entity_view_modes',
            // Add the entity-type for the options list callback.
            'options list entity type' => $type,
          ),
        ),
      );
    }

    // Specify that on presave the entity is saved anyway.
    $items[$type . '_presave']['variables'][$type]['skip save'] = TRUE;
    return $items;
  }

}

Members