You are here

function pathauto_entity_base_field_info in Pathauto 8

Implements hook_entity_base_field_info().

File

./pathauto.module, line 124
pathauto Pathauto: Automatically generates aliases for content

Code

function pathauto_entity_base_field_info(EntityTypeInterface $entity_type) {
  $config = \Drupal::config('pathauto.settings');

  // Verify that the configuration data isn't null (as is the case before the
  // module's initialization, in tests), so that in_array() won't fail.
  if ($enabled_entity_types = $config
    ->get('enabled_entity_types')) {
    if (in_array($entity_type
      ->id(), $enabled_entity_types)) {
      $fields['path'] = BaseFieldDefinition::create('path')
        ->setCustomStorage(TRUE)
        ->setLabel(t('URL alias'))
        ->setTranslatable(TRUE)
        ->setComputed(TRUE)
        ->setDisplayOptions('form', [
        'type' => 'path',
        'weight' => 30,
      ])
        ->setDisplayConfigurable('form', TRUE);
      return $fields;
    }
  }
}