/**
  * {@inheritdoc}
  */
 protected function alterViewTemplateAfterCreation(array &$view_template, $options = NULL)
 {
     parent::alterViewTemplateAfterCreation($view_template, $options);
     $field_defs = $this->field_manager->getBaseFieldDefinitions($this->getDefinitionValue('entity_type'));
     if (empty($field_defs['status'])) {
         // If entity doesn't have a base field status remove it from View filter.
         unset($view_template['display']['default']['display_options']['filters']['status']);
     }
     $this->field_manager->getFieldDefinitions($this->getDefinitionValue('entity_type'), 'event');
     $this->field_manager->getFieldStorageDefinitions('node');
 }
  /**
   * {@inheritdoc}
   */
  public function tableFields($bundles) {
    $info = $this->entityTypeManager->getDefinition($this->entityTypeId());
    $definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityTypeId());
    $label_key = $info->getKey('label');
    $label_field_label = t('Label');
    if ($label_key && isset($definitions[$label_key])) {
      $label_field_label = $definitions[$label_key]->getLabel();
    }
    $bundle_key = $info->getKey('bundle');
    $bundle_field_label = t('Type');
    if ($bundle_key && isset($definitions[$bundle_key])) {
      $bundle_field_label = $definitions[$bundle_key]->getLabel();
    }

    $fields = [];
    $fields['label'] = [
      'type' => 'label',
      'label' => $label_field_label,
      'weight' => 1,
    ];
    if (count($bundles) > 1) {
      $fields[$bundle_key] = [
        'type' => 'field',
        'label' => $bundle_field_label,
        'weight' => 2,
      ];
    }

    return $fields;
  }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('pathauto.settings');
     $form_state->cleanValues();
     $original_entity_types = $config->get('enabled_entity_types');
     foreach ($form_state->getValues() as $key => $value) {
         if ($key == 'enabled_entity_types') {
             $enabled_entity_types = [];
             foreach ($value as $entity_type_id => $enabled) {
                 $field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id);
                 // Verify that the entity type is enabled and that it is not defined
                 // or defined by us before adding it to the configuration, so that
                 // we do not store an entity type that cannot be enabled or disabled.
                 if ($enabled && (!isset($field_definitions['path']) || $field_definitions['path']->getProvider() === 'pathauto')) {
                     $enabled_entity_types[] = $entity_type_id;
                 }
             }
             $value = $enabled_entity_types;
         }
         $config->set($key, $value);
     }
     $config->save();
     // Clear cached field definitions if the values are changed.
     if ($original_entity_types != $config->get('enabled_entity_types')) {
         $this->entityFieldManager->clearCachedFieldDefinitions();
         $this->aliasTypeManager->clearCachedDefinitions();
     }
     parent::submitForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     // Register plugin managers used by Rules, but mock some unwanted
     // dependencies requiring more stuff to loaded.
     $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
     // Set all the modules as being existent.
     $this->enabledModules = new \ArrayObject();
     $this->enabledModules['rules'] = TRUE;
     $this->enabledModules['rules_test'] = TRUE;
     $enabled_modules = $this->enabledModules;
     $this->moduleHandler->moduleExists(Argument::type('string'))->will(function ($arguments) use($enabled_modules) {
         return [$arguments[0], $enabled_modules[$arguments[0]]];
     });
     // Wed don't care about alter() calls on the module handler.
     $this->moduleHandler->alter(Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn(NULL);
     $this->cacheBackend = new NullBackend('rules');
     $rules_directory = __DIR__ . '/../../..';
     $this->namespaces = new \ArrayObject(['Drupal\\rules' => $rules_directory . '/src', 'Drupal\\rules_test' => $rules_directory . '/tests/modules/rules_test/src', 'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData', 'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation']);
     $this->actionManager = new RulesActionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal());
     $this->conditionManager = new ConditionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal());
     $this->rulesExpressionManager = new ExpressionManager($this->namespaces, $this->moduleHandler->reveal());
     $this->classResolver = $this->prophesize(ClassResolverInterface::class);
     $this->typedDataManager = new TypedDataManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal(), $this->classResolver->reveal());
     $this->rulesDataProcessorManager = new DataProcessorManager($this->namespaces, $this->moduleHandler->reveal());
     $this->aliasManager = $this->prophesize(AliasManagerInterface::class);
     // Keep the deprecated entity manager around because it is still used in a
     // few places.
     $this->entityManager = $this->prophesize(EntityManagerInterface::class);
     $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
     $this->entityTypeManager->getDefinitions()->willReturn([]);
     $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
     $this->entityFieldManager->getBaseFieldDefinitions()->willReturn([]);
     $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
     $this->entityTypeBundleInfo->getBundleInfo()->willReturn([]);
     $this->dataFetcher = new DataFetcher();
     $this->dataFilterManager = new DataFilterManager($this->namespaces, $this->moduleHandler->reveal());
     $this->placeholderResolver = new PlaceholderResolver($this->dataFetcher, $this->dataFilterManager);
     $container->set('entity.manager', $this->entityManager->reveal());
     $container->set('entity_type.manager', $this->entityTypeManager->reveal());
     $container->set('entity_field.manager', $this->entityFieldManager->reveal());
     $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
     $container->set('context.repository', new LazyContextRepository($container, []));
     $container->set('path.alias_manager', $this->aliasManager->reveal());
     $container->set('plugin.manager.rules_action', $this->actionManager);
     $container->set('plugin.manager.condition', $this->conditionManager);
     $container->set('plugin.manager.rules_expression', $this->rulesExpressionManager);
     $container->set('plugin.manager.rules_data_processor', $this->rulesDataProcessorManager);
     $container->set('typed_data_manager', $this->typedDataManager);
     $container->set('string_translation', $this->getStringTranslationStub());
     $container->set('uuid', new Php());
     $container->set('typed_data.data_fetcher', $this->dataFetcher);
     $container->set('typed_data.placeholder_resolver', $this->placeholderResolver);
     \Drupal::setContainer($container);
     $this->container = $container;
 }
 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
         // An entity type must have a canonical link template and support fields.
         if ($entity_type->hasLinkTemplate('canonical') && is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class)) {
             $base_fields = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id);
             if (!isset($base_fields['path'])) {
                 // The entity type does not have a path field and is therefore not
                 // supported.
                 continue;
             }
             $this->derivatives[$entity_type_id] = $base_plugin_definition;
             $this->derivatives[$entity_type_id]['label'] = $entity_type->getLabel();
             $this->derivatives[$entity_type_id]['types'] = [$this->tokenEntityMapper->getTokenTypeForEntityType($entity_type_id)];
             $this->derivatives[$entity_type_id]['provider'] = $entity_type->getProvider();
             $this->derivatives[$entity_type_id]['context'] = [$entity_type_id => new ContextDefinition("entity:{$entity_type_id}", $this->t('@label being aliased', ['@label' => $entity_type->getLabel()]))];
         }
     }
     return $this->derivatives;
 }
 /**
  * {@inheritdoc}
  */
 public function getTableFields($bundles)
 {
     $definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id());
     $label_key = $this->entityType->getKey('label');
     $label_field_label = t('Label');
     if ($label_key && isset($definitions[$label_key])) {
         $label_field_label = $definitions[$label_key]->getLabel();
     }
     $bundle_key = $this->entityType->getKey('bundle');
     $bundle_field_label = t('Type');
     if ($bundle_key && isset($definitions[$bundle_key])) {
         $bundle_field_label = $definitions[$bundle_key]->getLabel();
     }
     $fields = [];
     $fields['label'] = ['type' => 'label', 'label' => $label_field_label, 'weight' => 1];
     if (count($bundles) > 1) {
         $fields[$bundle_key] = ['type' => 'field', 'label' => $bundle_field_label, 'weight' => 2, 'display_options' => ['type' => 'entity_reference_label', 'settings' => ['link' => FALSE]]];
     }
     return $fields;
 }