Exemple #1
0
 /**
  * Tests the clearCachedDefinitions() method.
  *
  * @covers ::clearCachedDefinitions
  */
 public function testClearCachedDefinitions()
 {
     $this->entityTypeManager->clearCachedDefinitions()->shouldBeCalled();
     $this->entityTypeRepository->clearCachedDefinitions()->shouldBeCalled();
     $this->entityTypeBundleInfo->clearCachedBundles()->shouldBeCalled();
     $this->entityFieldManager->clearCachedFieldDefinitions()->shouldBeCalled();
     $this->entityManager->clearCachedDefinitions();
 }
 /**
  * {@inheritdoc}
  */
 public function onBundleDelete($bundle, $entity_type_id)
 {
     $this->entityTypeBundleInfo->clearCachedBundles();
     // Notify the entity storage.
     $storage = $this->entityTypeManager->getStorage($entity_type_id);
     if ($storage instanceof EntityBundleListenerInterface) {
         $storage->onBundleDelete($bundle, $entity_type_id);
     }
     // Invoke hook_entity_bundle_delete() hook.
     $this->moduleHandler->invokeAll('entity_bundle_delete', [$entity_type_id, $bundle]);
     $this->entityFieldManager->clearCachedFieldDefinitions();
 }
 /**
  * {@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);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $values = $form_state->getValues();
     $this->config('ds.settings')->set('field_template', $values['fs1']['field_template'])->set('ft-default', $values['fs1']['ft-default'])->set('ft-show-colon', $values['fs1']['ft-show-colon'])->save();
     $this->entityFieldManager->clearCachedFieldDefinitions();
     $this->moduleHandler->resetImplementations();
     $this->themeRegistry->reset();
     $this->routeBuilder->setRebuildNeeded();
     \Drupal::cache('render')->deleteAll();
 }
 /**
  * {@inheritdoc}
  */
 public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $storage_definition)
 {
     $entity_type_id = $storage_definition->getTargetEntityTypeId();
     // @todo Forward this to all interested handlers, not only storage, once
     //   iterating handlers is possible: https://www.drupal.org/node/2332857.
     $storage = $this->entityTypeManager->getStorage($entity_type_id);
     if ($storage instanceof FieldStorageDefinitionListenerInterface) {
         $storage->onFieldStorageDefinitionDelete($storage_definition);
     }
     $this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::DELETE, new FieldStorageDefinitionEvent($storage_definition));
     $this->entityLastInstalledSchemaRepository->deleteLastInstalledFieldStorageDefinition($storage_definition);
     $this->entityFieldManager->clearCachedFieldDefinitions();
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $status = $this->entity->save();
     // Update the default value of the status field.
     $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $this->entity->id()]);
     $value = (bool) $form_state->getValue('product_status');
     if ($product->status->value != $value) {
         $fields = $this->entityFieldManager->getFieldDefinitions('commerce_product', $this->entity->id());
         $fields['status']->getConfig($this->entity->id())->setDefaultValue($value)->save();
         $this->entityFieldManager->clearCachedFieldDefinitions();
     }
     drupal_set_message($this->t('The product type %label has been successfully saved.', ['%label' => $this->entity->label()]));
     $form_state->setRedirect('entity.commerce_product_type.collection');
     if ($status == SAVED_NEW) {
         commerce_product_add_stores_field($this->entity);
         commerce_product_add_body_field($this->entity);
         commerce_product_add_variations_field($this->entity);
     }
 }