/**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     foreach ($entities as $entity) {
         entity_invoke_bundle_hook('delete', $entity->getEntityType()->getBundleOf(), $entity->id());
     }
 }
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     foreach ($entities as $entity) {
         $entity->deleteDisplays();
         \Drupal::entityManager()->onBundleDelete($entity->id(), $entity->getEntityType()->getBundleOf());
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $errors = $this->validate();
     if (!empty($errors)) {
         throw new EncryptException(implode(';', $errors));
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     // Make sure we save any explicit module dependencies.
     if ($provider = $this->get('module')) {
         $this->addDependency('module', $provider);
     }
     return $this->dependencies;
 }
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     if ($this->stateFrom) {
         $this->addDependency('config', ModerationState::load($this->stateFrom)->getConfigDependencyName());
     }
     if ($this->stateTo) {
         $this->addDependency('config', ModerationState::load($this->stateTo)->getConfigDependencyName());
     }
     return $this;
 }
Пример #6
0
 /**
  * Acts on an entity before the presave hook is invoked.
  *
  * Used before the entity is saved and before invoking the presave hook.
  *
  * Ensure that config entities which are bundles of other entities cannot have
  * their ID changed.
  *
  * @param \Drupal\Core\Entity\EntityStorageInterface $storage
  *   The entity storage object.
  *
  * @throws \Drupal\Core\Config\ConfigNameException
  *   Thrown when attempting to rename a bundle entity.
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Only handle renames, not creations.
     if (!$this->isNew() && $this->getOriginalId() !== $this->id()) {
         $bundle_type = $this->getEntityType();
         $bundle_of = $bundle_type->getBundleOf();
         if (!empty($bundle_of)) {
             throw new ConfigNameException("The machine name of the '{$bundle_type->getLabel()}' bundle cannot be changed.");
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     $prefix = $this->getModerationStateConfigPrefix() . '.';
     if ($this->stateFrom) {
         $this->addDependency('config', $prefix . $this->stateFrom);
     }
     if ($this->stateTo) {
         $this->addDependency('config', $prefix . $this->stateTo);
     }
     return $this;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     foreach ($entities as $entity) {
         $storage->deleteAssignedShortcutSets($entity);
         // Next, delete the shortcuts for this set.
         $shortcut_ids = \Drupal::entityQuery('shortcut')->condition('shortcut_set', $entity->id(), '=')->execute();
         $controller = \Drupal::entityManager()->getStorage('shortcut');
         $entities = $controller->loadMultiple($shortcut_ids);
         $controller->delete($entities);
     }
 }
Пример #9
0
 /**
  * @covers ::getThirdPartySetting
  * @covers ::setThirdPartySetting
  * @covers ::getThirdPartySettings
  * @covers ::unsetThirdPartySetting
  * @covers ::getThirdPartyProviders
  */
 public function testThirdPartySettings()
 {
     $key = 'test';
     $third_party = 'test_provider';
     $value = $this->getRandomGenerator()->string();
     // Test getThirdPartySetting() with no settings.
     $this->assertEquals($value, $this->entity->getThirdPartySetting($third_party, $key, $value));
     $this->assertNull($this->entity->getThirdPartySetting($third_party, $key));
     // Test setThirdPartySetting().
     $this->entity->setThirdPartySetting($third_party, $key, $value);
     $this->assertEquals($value, $this->entity->getThirdPartySetting($third_party, $key));
     $this->assertEquals($value, $this->entity->getThirdPartySetting($third_party, $key, $this->randomGenerator->string()));
     // Test getThirdPartySettings().
     $this->entity->setThirdPartySetting($third_party, 'test2', 'value2');
     $this->assertEquals(array($key => $value, 'test2' => 'value2'), $this->entity->getThirdPartySettings($third_party));
     // Test getThirdPartyProviders().
     $this->entity->setThirdPartySetting('test_provider2', $key, $value);
     $this->assertEquals(array($third_party, 'test_provider2'), $this->entity->getThirdPartyProviders());
     // Test unsetThirdPartyProviders().
     $this->entity->unsetThirdPartySetting('test_provider2', $key);
     $this->assertEquals(array($third_party), $this->entity->getThirdPartyProviders());
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public function postCreate(EntityStorageInterface $storage)
 {
     parent::postCreate($storage);
     // If it was not present in the $values passed to create(), (e.g. for
     // programmatic creation), populate the denormalized field_type property
     // from the field storage, so that it gets saved in the config record.
     if (empty($this->field_type)) {
         $this->field_type = $this->getFieldStorageDefinition()->getType();
     }
 }
Пример #11
0
 /**
  * Get all states in the system, with options to filter, only where a workflow exists.
  *
  * @_deprecated WorkflowState::getStates() ==> WorkflowState::loadMultiple()
  *
  * {@inheritdoc}
  *
  * @param $wid
  *   The requested Workflow ID.
  * @param bool $reset
  *   An option to refresh all caches.
  *
  * @return WorkflowState[] $states
  *   An array of cached states.
  */
 public static function loadMultiple(array $ids = NULL, $wid = '', $reset = FALSE)
 {
     if ($reset) {
         self::$states = array();
     }
     if (empty(self::$states)) {
         self::$states = parent::loadMultiple();
         usort(self::$states, ['Drupal\\workflow\\Entity\\WorkflowState', 'sort']);
     }
     if (!$wid) {
         // All states are requested and cached: return them.
         $result = self::$states;
     } else {
         // All states of only 1 Workflow is requested: return this one.
         // E.g., when called by Workflow->getStates().
         $result = array();
         foreach (self::$states as $state) {
             /* @var $state WorkflowState */
             if ($state->wid == $wid) {
                 $result[$state->id()] = $state;
             }
         }
     }
     return $result;
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     \Drupal::entityManager()->clearCachedFieldDefinitions();
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     static::routeBuilder()->setRebuildNeeded();
 }
Пример #14
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     $providers = \Drupal::service('breakpoint.manager')->getGroupProviders($this->breakpoint_group);
     foreach ($providers as $provider => $type) {
         $this->addDependency($type, $provider);
     }
     // Extract all the styles from the image style mappings.
     $styles = ImageStyle::loadMultiple($this->getImageStyleIds());
     array_walk($styles, function ($style) {
         $this->addDependency('config', $style->getConfigDependencyName());
     });
     return $this;
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function getCacheTags() {
   $tags = parent::getCacheTags();
   return Cache::mergeTags($tags, ['block_visibility_group:' . $this->id]);
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     $language_manager = \Drupal::languageManager();
     $language_manager->reset();
     $entity = reset($entities);
     if ($language_manager instanceof ConfigurableLanguageManagerInterface && !$entity->isUninstalling() && !$entity->isSyncing()) {
         $language_manager->updateLockedLanguageWeights();
     }
     // If after deleting this language the site will become monolingual, we need
     // to rebuild language services.
     if (!\Drupal::languageManager()->isMultilingual()) {
         ConfigurableLanguageManager::rebuildServices();
     }
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     if ($this->getPlugin()) {
         $this->addDependency('module', $this->getPlugin()->getPluginDefinition()['provider']);
     }
     return $this;
 }
Пример #18
0
 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // Clear the static caches of filter_formats() and others.
     filter_formats_reset();
     if (!$update && !$this->isSyncing()) {
         // Default configuration of modules and installation profiles is allowed
         // to specify a list of user roles to grant access to for the new format;
         // apply the defined user role permissions when a new format is inserted
         // and has a non-empty $roles property.
         // Note: user_role_change_permissions() triggers a call chain back into
         // \Drupal\filter\FilterPermissions::permissions() and lastly
         // filter_formats(), so its cache must be reset upfront.
         if (($roles = $this->get('roles')) && ($permission = $this->getPermissionName())) {
             foreach (user_roles() as $rid => $name) {
                 $enabled = in_array($rid, $roles, TRUE);
                 user_role_change_permissions($rid, array($permission => $enabled));
             }
         }
     }
 }
Пример #19
0
 /**
  * {@inheritdoc}
  */
 public function get($property_name)
 {
     if ($property_name == 'default') {
         return $this->isDefault();
     } else {
         return parent::get($property_name);
     }
 }
Пример #20
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     foreach ($entities as $style) {
         // Flush cached media for the deleted style.
         $style->flush();
         // Check whether field settings need to be updated.
         // In case no replacement style was specified, all image fields that are
         // using the deleted style are left in a broken state.
         if (!$style->isSyncing() && ($new_id = $style->getReplacementID())) {
             // The deleted ID is still set as originalID.
             $style->setName($new_id);
             static::replaceImageStyle($style);
         }
     }
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function delete()
 {
     foreach (array_keys($this->getLinks([], TRUE)) as $link_key) {
         $this->getMenuLinkManager()->removeDefinition($link_key, FALSE);
     }
     parent::delete();
 }
Пример #22
0
 /**
  * {@inheritdoc}
  */
 public function onDependencyRemoval(array $dependencies)
 {
     $changed = parent::onDependencyRemoval($dependencies);
     if (!isset($this->dependencies['enforced']['config'])) {
         return $changed;
     }
     $fix_deps = \Drupal::state()->get('config_test.fix_dependencies', array());
     foreach ($dependencies['config'] as $entity) {
         if (in_array($entity->getConfigDependencyName(), $fix_deps)) {
             $key = array_search($entity->getConfigDependencyName(), $this->dependencies['enforced']['config']);
             if ($key !== FALSE) {
                 $changed = TRUE;
                 unset($this->dependencies['enforced']['config'][$key]);
             }
         }
     }
     return $changed;
 }
Пример #23
0
 /**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $field_storages)
 {
     $state = \Drupal::state();
     // Set the static flag so that we don't delete field storages whilst
     // deleting fields.
     static::$inDeletion = TRUE;
     // Delete or fix any configuration that is dependent, for example, fields.
     parent::preDelete($storage, $field_storages);
     // Keep the field definitions in the state storage so we can use them later
     // during field_purge_batch().
     $deleted_storages = $state->get('field.storage.deleted') ?: array();
     foreach ($field_storages as $field_storage) {
         if (!$field_storage->deleted) {
             $config = $field_storage->toArray();
             $config['deleted'] = TRUE;
             $config['bundles'] = $field_storage->getBundles();
             $deleted_storages[$field_storage->uuid()] = $config;
         }
     }
     $state->set('field.storage.deleted', $deleted_storages);
 }
Пример #24
0
 /**
  * {@inheritdoc}
  */
 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
 {
     /** @var $a \Drupal\search\SearchPageInterface */
     /** @var $b \Drupal\search\SearchPageInterface */
     $a_status = (int) $a->status();
     $b_status = (int) $b->status();
     if ($a_status != $b_status) {
         return $a_status > $b_status ? -1 : 1;
     }
     return parent::sort($a, $b);
 }
Пример #25
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     foreach ($this->tipsCollection as $instance) {
         $definition = $instance->getPluginDefinition();
         $this->addDependency('module', $definition['provider']);
     }
     $this->addDependency('module', $this->module);
     return $this;
 }
Пример #26
0
 /**
  * Overrides Drupal\Core\Entity\Entity:preCreate().
  */
 public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
 {
     parent::preCreate($storage_controller, $values);
     $loader = \Drupal::service('domain.loader');
     $creator = \Drupal::service('domain.creator');
     $default = $loader->loadDefaultId();
     $domains = $loader->loadMultiple();
     $values += array('scheme' => empty($GLOBALS['is_https']) ? 'http' : 'https', 'status' => 1, 'weight' => count($domains) + 1, 'is_default' => (int) empty($default), 'domain_id' => $creator->createNextId());
 }
Пример #27
0
 /**
  * {@inheritdoc}
  */
 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
 {
     /** @var \Drupal\system\ActionConfigEntityInterface $a */
     /** @var \Drupal\system\ActionConfigEntityInterface $b */
     $a_type = $a->getType();
     $b_type = $b->getType();
     if ($a_type != $b_type) {
         return strnatcasecmp($a_type, $b_type);
     }
     return parent::sort($a, $b);
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     foreach ($this->test_dependencies as $type => $deps) {
         foreach ($deps as $dep) {
             $this->addDependency($type, $dep);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage_controller, $update = TRUE)
 {
     parent::postSave($storage_controller, $update);
     // Set bypass permissions.
     $roles = $this->getBypassRoles();
     $permission = $this->getPermissionName();
     if ($roles && $permission) {
         foreach (user_roles() as $rid => $name) {
             $enabled = in_array($rid, $roles, TRUE);
             user_role_change_permissions($rid, array($permission => $enabled));
         }
     }
 }
Пример #30
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     // Create a dependency on the associated FilterFormat.
     $this->addDependency('config', $this->getFilterFormat()->getConfigDependencyName());
     // @todo use EntityWithPluginCollectionInterface so configuration between
     //   config entity and dependency on provider is managed automatically.
     $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
     $this->addDependency('module', $definition['provider']);
     return $this->dependencies;
 }