/**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     if (!$update && !$this->isSyncing()) {
         block_content_add_body_field($this->id);
     }
 }
 /**
  * Disallows changing the machine name, during pre-save.
  *
  * If the machine name of the bundle was changed, all of the
  * existing entities with that bundle would be invalid.
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if (!$this->isNew() && $this->getOriginalId() != $this->id()) {
         throw new ConfigException('Cannot change machine name');
     }
 }
Exemple #3
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);
     }
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     // Clear the node type cache to reflect the removal.
     $storage->resetCache(array_keys($entities));
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public static function preCreate(EntityStorageInterface $storage, array &$values)
 {
     parent::preCreate($storage, $values);
     // Ensure default values are set.
     if (!isset($values['settings']['node'])) {
         $values['settings']['node'] = array();
     }
     $values['settings']['node'] = NestedArray::mergeDeep(array('options' => array('status' => TRUE, 'promote' => TRUE, 'sticky' => FALSE, 'revision' => FALSE), 'preview' => DRUPAL_OPTIONAL, 'submitted' => TRUE), $values['settings']['node']);
 }
 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     if (!$update && !$this->isSyncing()) {
         \Drupal::service('comment.manager')->addBodyField($this->id());
     }
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  *
  * @todo This does not scale.
  *
  * Deleting a contact type with thousands of contact records associated will
  * run into execution timeout.
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     $ids = array_map(function (EntityInterface $entity) {
         return $entity->id();
     }, $entities);
     // Delete all instances of the given type.
     $results = \Drupal::entityQuery('crm_core_contact')->condition('type', $ids, 'IN')->execute();
     if (!empty($results)) {
         $contacts = Contact::loadMultiple($results);
         \Drupal::entityManager()->getStorage('crm_core_contact')->delete($contacts);
         watchdog('crm_core_contact', 'Delete !count contacts due to deletion of contact type.', array('!count' => count($results)), WATCHDOG_INFO);
     }
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     $properties = parent::toArray();
     $properties['mappings'] = $this->mappings;
     return $properties;
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     // Clear the cache.
     $storage->resetCache(array($entities));
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // @todo Setting ->setRebuildNeeded isn't enough. Investigate.
     \Drupal::service('router.builder')->rebuild();
 }
 public function __construct(array $values = array(), $entity_type = 'field_collection')
 {
     parent::__construct($values, $entity_type);
     $this->entityType = 'field_collection';
 }
Exemple #12
0
  /**
   * {@inheritdoc}
   */
  public static function postLoad(EntityStorageInterface $storage, array &$entities) {
    parent::postLoad($storage, $entities);

    foreach ($entities as $queue) {
      $queue->getHandlerPlugin()->onQueuePostLoad($queue, $storage);
    }
  }
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     foreach ($entities as $entity) {
         entity_invoke_bundle_hook('delete', 'block_content', $entity->id());
     }
 }
 /**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     $registration_storage = \Drupal::entityManager()->getStorage('registration');
     /** @var \Drupal\rng\EventManagerInterface $event_manager */
     $event_manager = \Drupal::service('rng.event_manager');
     /** @var \Drupal\rng\RegistrationTypeInterface $registration_type */
     foreach ($entities as $registration_type) {
         // Remove entity field references in
         // $event->{EventManagerInterface::FIELD_REGISTRATION_TYPE}
         $event_types = $event_manager->getEventTypes();
         foreach ($event_types as $entity_type => $bundles) {
             $event_storage = \Drupal::entityManager()->getStorage($entity_type);
             foreach ($bundles as $bundle => $event_type) {
                 $bundle_key = \Drupal::entityManager()->getDefinition($entity_type)->getKey('bundle');
                 $ids = $event_storage->getQuery()->condition($bundle_key, $bundle)->condition(EventManagerInterface::FIELD_REGISTRATION_TYPE, $registration_type->id())->execute();
                 foreach ($ids as $id) {
                     $event_manager->getMeta($event_storage->load($id))->removeRegistrationType($registration_type->id())->save();
                 }
             }
         }
         // Remove registrations.
         $ids = $registration_storage->getQuery()->condition('type', $registration_type->id())->execute();
         $registrations = $registration_storage->loadMultiple($ids);
         $registration_storage->delete($registrations);
     }
     parent::preDelete($storage, $entities);
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  *
  * @todo This does not scale.
  *
  * Deleting a activity type with thousands of activities records associated
  * will run into execution timeout.
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     $ids = array_map(function (EntityInterface $entity) {
         return $entity->id();
     }, $entities);
     // Delete all instances of the given type.
     $results = \Drupal::entityQuery('crm_core_activity')->condition('type', $ids, 'IN')->execute();
     if (!empty($results)) {
         $activities = Activity::loadMultiple($results);
         \Drupal::entityManager()->getStorage('crm_core_activity')->delete($activities);
         // @todo Handle singular and plural.
         \Drupal::logger('crm_core_activity')->info('Delete !count activities due to deletion of activity type.', array('!count' => count($results)));
     }
 }
Exemple #16
0
 /**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     // Reset caches.
     $storage->resetCache(array_keys($entities));
     if (reset($entities)->isSyncing()) {
         return;
     }
     $vocabularies = array();
     foreach ($entities as $vocabulary) {
         $vocabularies[$vocabulary->id()] = $vocabulary->id();
     }
     // Load all Taxonomy module fields and delete those which use only this
     // vocabulary.
     $field_storages = entity_load_multiple_by_properties('field_storage_config', array('module' => 'taxonomy'));
     foreach ($field_storages as $field_storage) {
         $modified_storage = FALSE;
         // Term reference fields may reference terms from more than one
         // vocabulary.
         foreach ($field_storage->getSetting('allowed_values') as $key => $allowed_value) {
             if (isset($vocabularies[$allowed_value['vocabulary']])) {
                 $allowed_values = $field_storage->getSetting('allowed_values');
                 unset($allowed_values[$key]);
                 $field_storage->setSetting('allowed_values', $allowed_values);
                 $modified_storage = TRUE;
             }
         }
         if ($modified_storage) {
             $allowed_values = $field_storage->getSetting('allowed_values');
             if (empty($allowed_values)) {
                 $field_storage->delete();
             } else {
                 // Update the field definition with the new allowed values.
                 $field_storage->save();
             }
         }
     }
 }
Exemple #17
0
  /**
   * Sorts the flag entities, putting disabled flags at the bottom.
   *
   * @see \Drupal\Core\Config\Entity\ConfigEntityBase::sort()
   */
  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {

    // Check if the entities are flags, if not go with the default.
    if ($a instanceof FlagInterface && $b instanceof FlagInterface) {

      if ($a->isEnabled() && $b->isEnabled()) {
        return parent::sort($a, $b);
      }
      elseif (!$a->isEnabled()) {
        return -1;
      }
      elseif (!$b->isEnabled()) {
        return 1;
      }
    }

    return parent::sort($a, $b);
  }