protected function ParagraphsConversionManager::isApplicable

Returns whether the given plugin is applicable for the conversion.

Parameters

\Drupal\paragraphs\ParagraphsConversionInterface $plugin: The conversion plugin.

\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.

array|null $allowed_types: (optional) The list of allowed types.

Return value

bool TRUE if the plugin is applicable. Otherwise, FALSE.

2 calls to ParagraphsConversionManager::isApplicable()
ParagraphsConversionManager::getApplicableDefinitions in paragraphs/src/ParagraphsConversionManager.php
Gets the applicable conversion plugins.
ParagraphsConversionManager::supportsConversion in paragraphs/src/ParagraphsConversionManager.php
Checks if the paragraph supports conversion.

File

paragraphs/src/ParagraphsConversionManager.php, line 94

Class

ParagraphsConversionManager
Plugin type manager for paragraphs type conversion plugins.

Namespace

Drupal\paragraphs

Code

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;
}