You are here

public static function Feed::baseFieldDefinitions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/aggregator/src/Entity/Feed.php \Drupal\aggregator\Entity\Feed::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 FieldableEntityInterface::baseFieldDefinitions

See also

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

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

File

core/modules/aggregator/src/Entity/Feed.php, line 134
Contains \Drupal\aggregator\Entity\Feed.

Class

Feed
Defines the aggregator feed entity class.

Namespace

Drupal\aggregator\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields['fid'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Feed ID'))
    ->setDescription(t('The ID of the aggregator feed.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The aggregator feed UUID.'))
    ->setReadOnly(TRUE);
  $fields['title'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setDescription(t('The name of the feed (or the name of the website providing the feed).'))
    ->setRequired(TRUE)
    ->setSetting('max_length', 255)
    ->setDisplayOptions('form', array(
    'type' => 'string_textfield',
    'weight' => -5,
  ))
    ->setDisplayConfigurable('form', TRUE)
    ->addConstraint('FeedTitle');
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language code'))
    ->setDescription(t('The feed language code.'))
    ->setDisplayOptions('view', array(
    'type' => 'hidden',
  ))
    ->setDisplayOptions('form', array(
    'type' => 'language_select',
    'weight' => 2,
  ));
  $fields['url'] = BaseFieldDefinition::create('uri')
    ->setLabel(t('URL'))
    ->setDescription(t('The fully-qualified URL of the feed.'))
    ->setRequired(TRUE)
    ->setDisplayOptions('form', array(
    'type' => 'uri',
    'weight' => -3,
  ))
    ->setDisplayConfigurable('form', TRUE)
    ->addConstraint('FeedUrl');
  $intervals = array(
    900,
    1800,
    3600,
    7200,
    10800,
    21600,
    32400,
    43200,
    64800,
    86400,
    172800,
    259200,
    604800,
    1209600,
    2419200,
  );
  $period = array_map(array(
    \Drupal::service('date.formatter'),
    'formatInterval',
  ), array_combine($intervals, $intervals));
  $period[AGGREGATOR_CLEAR_NEVER] = t('Never');
  $fields['refresh'] = BaseFieldDefinition::create('list_integer')
    ->setLabel(t('Update interval'))
    ->setDescription(t('The length of time between feed updates. Requires a correctly configured cron maintenance task.'))
    ->setSetting('unsigned', TRUE)
    ->setRequired(TRUE)
    ->setSetting('allowed_values', $period)
    ->setDisplayOptions('form', array(
    'type' => 'options_select',
    'weight' => -2,
  ))
    ->setDisplayConfigurable('form', TRUE);
  $fields['checked'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Checked'))
    ->setDescription(t('Last time feed was checked for new items, as Unix timestamp.'))
    ->setDefaultValue(0)
    ->setDisplayOptions('view', array(
    'label' => 'inline',
    'type' => 'timestamp_ago',
    'weight' => 1,
  ))
    ->setDisplayConfigurable('view', TRUE);
  $fields['queued'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Queued'))
    ->setDescription(t('Time when this feed was queued for refresh, 0 if not queued.'))
    ->setDefaultValue(0);
  $fields['link'] = BaseFieldDefinition::create('uri')
    ->setLabel(t('URL'))
    ->setDescription(t('The link of the feed.'))
    ->setDisplayOptions('view', array(
    'label' => 'inline',
    'weight' => 4,
  ))
    ->setDisplayConfigurable('view', TRUE);
  $fields['description'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Description'))
    ->setDescription(t("The parent website's description that comes from the @description element in the feed.", array(
    '@description' => '<description>',
  )));
  $fields['image'] = BaseFieldDefinition::create('uri')
    ->setLabel(t('Image'))
    ->setDescription(t('An image representing the feed.'));
  $fields['hash'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Hash'))
    ->setSetting('is_ascii', TRUE)
    ->setDescription(t('Calculated hash of the feed data, used for validating cache.'));
  $fields['etag'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Etag'))
    ->setDescription(t('Entity tag HTTP response header, used for validating cache.'));

  // This is updated by the fetcher and not when the feed is saved, therefore
  // it's a timestamp and not a changed field.
  $fields['modified'] = BaseFieldDefinition::create('timestamp')
    ->setLabel(t('Modified'))
    ->setDescription(t('When the feed was last modified, as a Unix timestamp.'));
  return $fields;
}