class RemoveNonPublicFiles in Acquia Content Hub 8.2
Class RemoveNonPublicFiles.
Removes dependency on non-public files.
@package Drupal\acquia_contenthub\EventSubscriber\FilterDeps
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\FilterDeps\RemoveNonPublicFiles implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RemoveNonPublicFiles
1 string reference to 'RemoveNonPublicFiles'
1 service uses RemoveNonPublicFiles
File
- src/
EventSubscriber/ FilterDeps/ RemoveNonPublicFiles.php, line 20
Namespace
Drupal\acquia_contenthub\EventSubscriber\FilterDepsView source
class RemoveNonPublicFiles implements EventSubscriberInterface {
/**
* The file scheme handler manager.
*
* @var \Drupal\acquia_contenthub\Plugin\FileSchemeHandler\FileSchemeHandlerManagerInterface
*/
protected $manager;
/**
* RemoveNonPublicFiles constructor.
*
* @param \Drupal\acquia_contenthub\Plugin\FileSchemeHandler\FileSchemeHandlerManagerInterface $manager
* The file scheme handler manager service.
*/
public function __construct(FileSchemeHandlerManagerInterface $manager) {
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[DependencyCalculatorEvents::FILTER_FIELDS][] = [
'onFilterFields',
1001,
];
$events[AcquiaContentHubEvents::SERIALIZE_CONTENT_ENTITY_FIELD][] = [
'onSerializeContentField',
1001,
];
return $events;
}
/**
* Filter fields.
*
* @param \Drupal\depcalc\Event\FilterDependencyCalculationFieldsEvent $event
* Filter Dependency Calculation Fields.
*/
public function onFilterFields(FilterDependencyCalculationFieldsEvent $event) {
$fields = array_filter($event
->getFields(), function ($field) {
return $this
->includeField($field);
}, ARRAY_FILTER_USE_BOTH);
$event
->setFields(...$fields);
}
/**
* Serialize content field event.
*
* @param \Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent $event
* Serialized CDF Entity Field event.
*/
public function onSerializeContentField(SerializeCdfEntityFieldEvent $event) {
$field = $event
->getField();
if (!$this
->includeField($field)) {
$event
->setExcluded();
$event
->stopPropagation();
}
}
/**
* Whether we should include this field in the dependency calculation.
*
* @param \Drupal\Core\Field\FieldItemListInterface $field
* The entity field.
*
* @return bool
* TRUE if we should include the field, FALSE otherwise.
*/
protected function includeField(FieldItemListInterface $field) {
$definition = $field
->getFieldDefinition();
if (!in_array($definition
->getType(), [
'file',
'image',
], TRUE)) {
return TRUE;
}
return $this->manager
->hasDefinition($definition
->getFieldStorageDefinition()
->getSetting('uri_scheme'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RemoveNonPublicFiles:: |
protected | property | The file scheme handler manager. | |
RemoveNonPublicFiles:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RemoveNonPublicFiles:: |
protected | function | Whether we should include this field in the dependency calculation. | |
RemoveNonPublicFiles:: |
public | function | Filter fields. | |
RemoveNonPublicFiles:: |
public | function | Serialize content field event. | |
RemoveNonPublicFiles:: |
public | function | RemoveNonPublicFiles constructor. |