You are here

function type_style_moderation_get_styles in Type Style 8

Helper function to grab all plugin styles for a given workflow.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A workflow entity, or an entity which has a workflow.

string $plugin: The name of the workflow plugin (i.e. transitions/states).

string $plugin_id: The workflow plugin ID (i.e. draft).

Return value

array An associative array of styles. Values are safe to use.

1 call to type_style_moderation_get_styles()
type_style_moderation_get_style in modules/type_style_moderation/type_style_moderation.module
Helper function to grab a plugin style for a given workflow.

File

modules/type_style_moderation/type_style_moderation.module, line 115
Hook implementations for the Type Style Moderation module.

Code

function type_style_moderation_get_styles(EntityInterface $entity, $plugin, $plugin_id) {
  if ($entity
    ->getEntityTypeId() === 'workflow') {
    $workflow = $entity;
  }
  elseif ($entity instanceof ContentEntityInterface && \Drupal::moduleHandler()
    ->moduleExists('content_moderation')) {

    /** @var \Drupal\content_moderation\ModerationInformationInterface $information */
    $information = \Drupal::service('content_moderation.moderation_information');
    $workflow = $information
      ->getWorkflowForEntity($entity);
  }
  if (!isset($workflow) || !$workflow) {
    return [];
  }
  $type_plugin = $workflow
    ->getTypePlugin();
  $config = $type_plugin
    ->getConfiguration();
  $styles = isset($config[$plugin][$plugin_id]['type_style']) ? $config[$plugin][$plugin_id]['type_style'] : [];
  return preg_replace('/[^a-zA-Z0-9\\-\\_\\#]/', '', $styles);
}