abstract class OgDeleteOrphansBase in Organic groups 8
Base implementation for OgDeleteOrphans plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\og\OgDeleteOrphansBase implements ContainerFactoryPluginInterface, OgDeleteOrphansInterface uses StringTranslationTrait
Expanded class hierarchy of OgDeleteOrphansBase
3 files declare their use of OgDeleteOrphansBase
- Batch.php in src/
Plugin/ OgDeleteOrphans/ Batch.php - Cron.php in src/
Plugin/ OgDeleteOrphans/ Cron.php - Simple.php in src/
Plugin/ OgDeleteOrphans/ Simple.php
File
- src/
OgDeleteOrphansBase.php, line 19
Namespace
Drupal\ogView source
abstract class OgDeleteOrphansBase extends PluginBase implements OgDeleteOrphansInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The queue factory.
*
* @var \Drupal\Core\Queue\QueueFactory
*/
protected $queueFactory;
/**
* The OG membership manager.
*
* @var \Drupal\og\MembershipManagerInterface
*/
protected $membershipManager;
/**
* The OG group audience helper.
*
* @var \Drupal\og\OgGroupAudienceHelperInterface
*/
protected $groupAudienceHelper;
/**
* Constructs an OgDeleteOrphansBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Queue\QueueFactory $queue_factory
* The queue factory.
* @param \Drupal\og\MembershipManagerInterface $membership_manager
* The OG membership manager service.
* @param \Drupal\og\OgGroupAudienceHelperInterface $group_audience_helper
* The OG group audience helper.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, QueueFactory $queue_factory, MembershipManagerInterface $membership_manager, OgGroupAudienceHelperInterface $group_audience_helper) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->queueFactory = $queue_factory;
$this->membershipManager = $membership_manager;
$this->groupAudienceHelper = $group_audience_helper;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('queue'), $container
->get('og.membership_manager'), $container
->get('og.group_audience_helper'));
}
/**
* {@inheritdoc}
*/
public function register(EntityInterface $entity) {
foreach ($this
->query($entity) as $entity_type => $orphans) {
foreach ($orphans as $orphan) {
$this
->getQueue()
->createItem([
'type' => $entity_type,
'id' => $orphan,
]);
}
}
}
/**
* Queries the registered group entity for orphaned members to delete.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The group entity that is the basis for the query.
*
* @return array
* An associative array, keyed by entity type, each item an array of entity
* IDs to delete.
*/
protected function query(EntityInterface $entity) {
// Register orphaned group content.
$orphans = $this->membershipManager
->getGroupContentIds($entity);
// Register orphaned user memberships.
$membership_ids = $this->entityTypeManager
->getStorage('og_membership')
->getQuery()
->condition('entity_type', $entity
->getEntityTypeId())
->condition('entity_id', $entity
->id())
->execute();
if (!empty($membership_ids)) {
$orphans['og_membership'] = $membership_ids;
}
return $orphans;
}
/**
* Deletes an orphaned group content entity if it is fully orphaned.
*
* @param string $entity_type
* The group content entity type.
* @param string $entity_id
* The group content entity ID.
*/
protected function deleteOrphan($entity_type, $entity_id) {
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
// The entity might already be removed by other modules that implement
// hook_entity_delete().
if (!$entity) {
return;
}
// Only delete group content that is fully orphaned, i.e. it is no longer
// associated with any groups.
if ($this->groupAudienceHelper
->hasGroupAudienceField($entity
->getEntityTypeId(), $entity
->bundle())) {
// Only do a group count if the entity is actually group content.
$group_count = $this->membershipManager
->getGroupCount($entity);
if ($group_count == 0) {
$entity
->delete();
}
}
else {
$entity
->delete();
}
}
/**
* Returns the queue of orphans to delete.
*
* @return \Drupal\Core\Queue\QueueInterface
* The queue.
*/
protected function getQueue() {
return $this->queueFactory
->get('og_orphaned_group_content', TRUE);
}
/**
* {@inheritdoc}
*/
public function configurationForm(array $form, FormStateInterface $form_state) {
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OgDeleteOrphansBase:: |
protected | property | The entity type manager. | |
OgDeleteOrphansBase:: |
protected | property | The OG group audience helper. | |
OgDeleteOrphansBase:: |
protected | property | The OG membership manager. | |
OgDeleteOrphansBase:: |
protected | property | The queue factory. | |
OgDeleteOrphansBase:: |
public | function |
Returns the configuration form elements specific to this plugin. Overrides OgDeleteOrphansInterface:: |
1 |
OgDeleteOrphansBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
OgDeleteOrphansBase:: |
protected | function | Deletes an orphaned group content entity if it is fully orphaned. | |
OgDeleteOrphansBase:: |
protected | function | Returns the queue of orphans to delete. | 1 |
OgDeleteOrphansBase:: |
protected | function | Queries the registered group entity for orphaned members to delete. | |
OgDeleteOrphansBase:: |
public | function |
Registers a soon to be deleted group entity, for processing. Overrides OgDeleteOrphansInterface:: |
1 |
OgDeleteOrphansBase:: |
public | function |
Constructs an OgDeleteOrphansBase object. Overrides PluginBase:: |
|
OgDeleteOrphansInterface:: |
public | function | Starts the deletion process. | 3 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |