You are here

function _insert_render in Insert 8.2

Returns the rendered template for a specific style or pseudo-style.

Parameters

string $styleName:

array $vars:

Return value

string

1 call to _insert_render()
_insert_field_process in ./insert.module
Form API callback: Processes a file field element.

File

./insert.module, line 372

Code

function _insert_render($styleName, array $vars) {
  $rendered = \Drupal::moduleHandler()
    ->invokeAll('insert_render', [
    $styleName,
    $vars,
  ]);
  if (count($rendered)) {
    $rendered = $rendered[0];
  }
  else {
    if ($styleName === 'insert__auto') {
      $styleName = isset($vars['insert__auto']) ? $vars['insert__auto'] : 'link';
    }
    if ($styleName === 'icon_link') {
      $rendered = \Drupal::theme()
        ->render([
        'insert_icon_link',
      ], $vars);
    }
    elseif ($styleName === 'link') {
      $rendered = \Drupal::theme()
        ->render([
        'insert_link',
      ], $vars);
    }
    elseif ($styleName === 'audio') {
      $rendered = \Drupal::theme()
        ->render([
        'insert_audio',
      ], $vars);
    }
    elseif ($styleName === 'video') {
      $rendered = \Drupal::theme()
        ->render([
        'insert_video',
      ], $vars);
    }
    else {
      $templateStyleName = str_replace('-', '_', $styleName);
      $templateFieldName = str_replace('-', '_', $vars['field_name']);
      $rendered = \Drupal::theme()
        ->render([
        'insert_image__' . $templateFieldName . '__' . $templateStyleName,
        'insert_image__' . $templateFieldName,
        'insert_image__' . $templateStyleName,
        'insert_image',
      ], $vars);
    }
  }
  return gettype($rendered) === 'string' ? $rendered : $rendered
    ->jsonSerialize();
}