Returns whether the given plugin is applicable for the conversion.
\Drupal\paragraphs\ParagraphsConversionInterface $plugin: The conversion plugin.
\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.
array|null $allowed_types: (optional) The list of allowed types.
bool TRUE if the plugin is applicable. Otherwise, FALSE.
protected function isApplicable(ParagraphsConversionInterface $plugin, ParagraphInterface $paragraph, array $allowed_types = NULL) {
if (!$plugin
->supports($paragraph, $allowed_types)) {
return FALSE;
}
$target_types = $plugin
->getPluginDefinition()['target_types'];
if (empty($target_types)) {
return TRUE;
}
// Check create access of the target paragraph type.
$access_control_handler = $this->entityTypeManager
->getAccessControlHandler($paragraph
->getEntityTypeId());
// Loop over the target types and check that the user has create
// access to all of them.
foreach ($target_types as $target_type) {
if (!$access_control_handler
->createAccess($target_type)) {
return FALSE;
}
// In case there are allowed types check the target type.
if (is_array($allowed_types) && !isset($allowed_types[$target_type])) {
return FALSE;
}
}
return TRUE;
}