You are here

public static function Rule::baseFieldDefinitions in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Rule.php \Drupal\rng\Entity\Rule::baseFieldDefinitions()
  2. 3.x src/Entity/Rule.php \Drupal\rng\Entity\Rule::baseFieldDefinitions()

Provides base field definitions for an entity type.

Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:

$fields['name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('Name'));

By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().

The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.

Overrides ContentEntityBase::baseFieldDefinitions

See also

\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()

\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()

File

src/Entity/Rule.php, line 185

Class

Rule
Defines the event rule entity.

Namespace

Drupal\rng\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Rule ID'))
    ->setDescription(t('The rule ID.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['event'] = BaseFieldDefinition::create('dynamic_entity_reference')
    ->setLabel(t('Event'))
    ->setDescription(t('Select event to associate with this rule.'))
    ->setRequired(TRUE)
    ->setReadOnly(TRUE);
  $fields['trigger_id'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Trigger'))
    ->setDescription(t('The trigger ID for this rule.'))
    ->setRequired(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created on'))
    ->setDescription(t('The time that the rule was created.'));
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The last time the rule was edited.'));
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Status'))
    ->setDescription(t('Whether this rule should run if the trigger is used. 0=disabled, 1=active.'))
    ->setDefaultValue(FALSE)
    ->setRequired(TRUE);
  return $fields;
}