preDelete example


    }
    else {
      $menu_link_manager->addDefinition($this->getPluginId()$definition);
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
    $menu_link_manager = \Drupal::service('plugin.manager.menu.link');

    foreach ($entities as $menu_link) {
      /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
      $menu_link_manager->removeDefinition($menu_link->getPluginId(), FALSE);

      // Children get re-attached to the menu link's parent.       $parent_plugin_id = $menu_link->getParentId();
      $children = $storage->loadByProperties(['parent' => $menu_link->getPluginId()]);
      
// Our mocked entity->postCreate() returns NULL, so assert that.     $this->assertNull($this->entity->postCreate($storage));
  }

  /** * @covers ::preDelete */
  public function testPreDelete() {
    // This method is internal, so check for errors on calling it only.     $storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    // Our mocked entity->preDelete() returns NULL, so assert that.     $this->assertNull($this->entity->preDelete($storage[$this->entity]));
  }

  /** * @covers ::postDelete */
  public function testPostDelete() {
    $this->cacheTagsInvalidator->expects($this->once())
      ->method('invalidateTags')
      ->with([
        $this->entityTypeId . '_list',
        $this->entityTypeId . ':' . $this->values['id'],
      ]);

  public function delete(array $entities) {
    if (!$entities) {
      // If no entities were passed, do nothing.       return;
    }

    $entities_by_class = $this->getEntitiesByClass($entities);

    // Allow code to run before deleting.     foreach ($entities_by_class as $entity_class => &$items) {
      $entity_class::preDelete($this$items);
      foreach ($items as $entity) {
        $this->invokeHook('predelete', $entity);
      }

      // Perform the delete and reset the static cache for the deleted entities.       $this->doDelete($items);
      $this->resetCache(array_keys($items));

      // Allow code to run after deleting.       $entity_class::postDelete($this$items);
      foreach ($items as $entity) {
        
/** * {@inheritdoc} */
  public function getThirdPartyProviders() {
    return array_keys($this->third_party_settings);
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    foreach ($entities as $entity) {
      if ($entity->isUninstalling() || $entity->isSyncing()) {
        // During extension uninstall and configuration synchronization         // deletions are already managed.         break;
      }
      // Fix or remove any dependencies.       $config_entities = static::getConfigManager()->getConfigEntitiesToChangeOnDependencyRemoval('config', [$entity->getConfigDependencyName()], FALSE);
      /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $dependent_entity */
      foreach ($config_entities['update'] as $dependent_entity) {
        
$shortcut->shortcut_set->target_id = $this->id();
          $shortcut->save();
        }
      }
    }
  }

  /** * {@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')
        ->accessCheck(FALSE)
        ->condition('shortcut_set', $entity->id(), '=')
        ->execute();

      $controller = \Drupal::entityTypeManager()->getStorage('shortcut');
      
/** * {@inheritdoc} */
  public function isLocked() {
    return (bool) $this->locked;
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);
    /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
    $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
    foreach ($entities as $menu) {
      // Delete all links from the menu.       $menu_link_manager->deleteLinksInMenu($menu->id());
    }
  }

  /** * {@inheritdoc} */
  
// Reindex the node when it is updated. The node is automatically indexed     // when it is added, simply by being added to the node table.     if ($update) {
      node_reindex_node_search($this->id());
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    // Ensure that all nodes deleted are removed from the search index.     if (\Drupal::hasService('search.index')) {
      /** @var \Drupal\search\SearchIndexInterface $search_index */
      $search_index = \Drupal::service('search.index');
      foreach ($entities as $entity) {
        $search_index->clear('node_search', $entity->nid->value);
      }
    }
  }

  

  public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
    /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
    $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');

    // 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 storage definitions in the deleted fields repository so we     // can use them later during field_purge_batch().     /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
    foreach ($field_storages as $field_storage) {
      // Only mark a field for purging if there is data. Otherwise, just remove       // it.       $target_entity_storage = \Drupal::entityTypeManager()->getStorage($field_storage->getTargetEntityTypeId());
      if (!$field_storage->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field_storage, TRUE)) {
        $storage_definition = clone $field_storage;
        $storage_definition->deleted = TRUE;
        

  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);

    $this->mergeDefaultDisplaysOptions();
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    // Call the remove() hook on the individual displays.     /** @var \Drupal\views\ViewEntityInterface $entity */
    foreach ($entities as $entity) {
      $executable = Views::executableFactory()->get($entity);
      foreach ($entity->get('display') as $display_id => $display) {
        $executable->setDisplay($display_id);
        $executable->getDisplay()->remove();
      }
    }
  }

  

  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);
    $this->postCreateCount++;
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);
    self::$preDeleteCount++;
  }

  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);
    self::$postDeleteCount++;
  }

  
// Set size unless there was an error.     if ($size !== FALSE) {
      $this->setSize($size);
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    foreach ($entities as $entity) {
      // Delete all remaining references to this file.       $file_usage = \Drupal::service('file.usage')->listUsage($entity);
      if (!empty($file_usage)) {
        foreach ($file_usage as $module => $usage) {
          \Drupal::service('file.usage')->delete($entity$module);
        }
      }
      // Delete the actual file. Failures due to invalid files and files that       // were already deleted are logged to watchdog but ignored, the
/** * {@inheritdoc} */
  public function getDescription() {
    return $this->description;
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    // Only load terms without a parent, child terms will get deleted too.     $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
    $terms = $term_storage->loadMultiple($storage->getToplevelTids(array_keys($entities)));
    $term_storage->delete($terms);
  }

  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    

  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
  }

  /** * {@inheritdoc} */
  protected function urlRouteParameters($rel) {
    $uri_route_parameters = parent::urlRouteParameters($rel);
    if ($rel === 'add-form') {
      $uri_route_parameters['entity_type_id'] = $this->getTargetType();
    }

    
return $this;
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $fields) {
    /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
    $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');
    $entity_type_manager = \Drupal::entityTypeManager();

    parent::preDelete($storage$fields);

    // Keep the field definitions in the deleted fields repository so we can use     // them later during field_purge_batch().     /** @var \Drupal\field\FieldConfigInterface $field */
    foreach ($fields as $field) {
      // Only mark a field for purging if there is data. Otherwise, just remove       // it.       $target_entity_storage = $entity_type_manager->getStorage($field->getTargetEntityTypeId());
      if (!$field->deleted && $target_entity_storage instanceof FieldableEntityStorageInterface && $target_entity_storage->countFieldData($field->getFieldStorageDefinition(), TRUE)) {
        $field = clone $field;
        $field->deleted = TRUE;
        
public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);
    if ($this->isReusable() || (isset($this->original) && $this->original->isReusable())) {
      static::invalidateBlockPluginCache();
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    /** @var \Drupal\block_content\BlockContentInterface $block */
    foreach ($entities as $block) {
      foreach ($block->getInstances() as $instance) {
        $instance->delete();
      }
    }
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.