You are here

function smart_title_preprocess in Smart Title 8

Implements hook_preprocess().

File

./smart_title.module, line 106
Contains hooks and private functions of smart_title.module.

Code

function smart_title_preprocess(&$variables, $hook) {
  $bundle_info = \Drupal::service('entity_type.bundle.info')
    ->getBundleInfo($hook);
  if (!empty($bundle_info)) {

    // Restoring configurable base fields which's original output is hidden for
    // example by template_preprocess_node().
    foreach (_smart_title_view_configurable_base_fields($hook) as $base_field_name) {
      if (!empty($variables['content']["smart__temp_{$base_field_name}"])) {
        $variables['content'][$base_field_name] = $variables['content']["smart__temp_{$base_field_name}"];
        unset($variables['content']["smart__temp_{$base_field_name}"]);
      }
    }

    // Determine whether the `page` property should be set to TRUE to prevent
    // rendering the original label.
    $evdIdArr = [
      'type' => $hook,
    ];
    if (!empty($variables['elements']['#' . $hook])) {
      $evdIdArr['viewMode'] = $variables['elements']['#' . $hook]
        ->bundle();
    }
    $evdStorage = \Drupal::service('entity_type.manager')
      ->getStorage('entity_view_display');
    $evd = isset($variables['view_mode']) && $evdStorage
      ->load(implode('.', $evdIdArr + [
      $variables['view_mode'],
    ])) ? $evdStorage
      ->load(implode('.', $evdIdArr + [
      $variables['view_mode'],
    ])) : $evdStorage
      ->load(implode('.', $evdIdArr + [
      'default',
    ]));
    if ($evd && $evd
      ->getThirdPartySetting('smart_title', 'enabled') && isset($variables['page'])) {
      $variables['page'] = TRUE;
    }
  }
}