function fontyourface_preprocess_font in @font-your-face 8.3
Prepares variables for Font templates.
Default template: font.html.twig.
Parameters
array $variables: An associative array containing:
- elements: An associative array containing the user information and any
- attributes: HTML attributes for the containing element.
2 calls to fontyourface_preprocess_font()
- fontyourface_preprocess_font__full in ./
fontyourface.module - Prepares variables for Font templates.
- fontyourface_preprocess_font__teaser in ./
fontyourface.module - Prepares variables for font teaser preview.
File
- ./
fontyourface.module, line 163 - Contains fontyourface.module..
Code
function fontyourface_preprocess_font(array &$variables) {
// Fetch Font Entity Object.
$font = $variables['elements']['#font'];
$fonts =& drupal_static('fontyourface_fonts');
$fonts[$font->url->value] = $font;
$font_preview =& drupal_static('fontyourface_font_preview');
$font_preview = TRUE;
$title = Html::escape($font->name->value);
$variables['font_style'] = fontyourface_font_css($font, NULL, "\n");
$variables['font_style_inline'] = fontyourface_font_css($font);
$variables['font_title'] = Link::fromTextAndUrl($title, $font
->toUrl())
->toString();
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
$variables['attributes']['class'] = [
'font',
];
if ($font
->isDeactivated()) {
$url = Url::fromRoute('entity.font.activate', [
'js' => 'nojs',
'font' => $font
->id(),
], [
'query' => \Drupal::destination()
->getAsArray(),
]);
$url
->setOptions([
'attributes' => [
'id' => 'font-status-' . $font
->id(),
'class' => [
'font-status',
'disabled',
'use-ajax',
],
],
]);
$text = t('Enable');
$variables['attributes']['class'][] = 'disabled';
}
if ($font
->isActivated()) {
$url = Url::fromRoute('entity.font.deactivate', [
'js' => 'nojs',
'font' => $font
->id(),
], [
'query' => \Drupal::destination()
->getAsArray(),
]);
$url
->setOptions([
'attributes' => [
'id' => 'font-status-' . $font
->id(),
'class' => [
'font-status',
'enabled',
'use-ajax',
],
],
]);
$text = t('Disable');
$variables['attributes']['class'][] = 'enabled';
}
$url
->setOption('destination', Drupal::destination());
$variables['operation_links'] = Link::fromTextAndUrl($text, $url)
->toString();
}