filterManager = $filter_manager; $this->filterStorage = $entity_type_manager->getStorage('filter_format'); $this->stringTranslation = $string_translation; } /** * {@inheritdoc} */ public function validate($module) { $reasons = []; // Get filter plugins supplied by this module. if ($filter_plugins = $this->getFilterDefinitionsByProvider($module)) { $used_in = []; // Find out if any filter formats have the plugin enabled. foreach ($this->getEnabledFilterFormats() as $filter_format) { $filters = $filter_format->filters(); foreach ($filter_plugins as $filter_plugin) { if ($filters->has($filter_plugin['id']) && $filters->get($filter_plugin['id'])->status) { $used_in[] = $filter_format->label(); break; } } } if (!empty($used_in)) { $reasons[] = $this->t('Provides a filter plugin that is in use in the following filter formats: %formats', ['%formats' => implode(', ', $used_in)]); } } return $reasons; } /** * Returns all filter definitions that are provided by the specified provider. * * @param string $provider * The provider of the filters. * * @return array * The filter definitions for the specified provider. */ protected function getFilterDefinitionsByProvider($provider) { return array_filter($this->filterManager->getDefinitions(), function ($definition) use ($provider) { return $definition['provider'] == $provider; }); } /** * Returns all enabled filter formats. * * @return \Drupal\filter\FilterFormatInterface[] */ protected function getEnabledFilterFormats() { return $this->filterStorage->loadByProperties(['status' => TRUE]); } }