function amp_preprocess_block in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.3 amp.module \amp_preprocess_block()
Implements hook_preprocess_block() for block templates.
File
- ./
amp.module, line 427
Code
function amp_preprocess_block(&$variables) {
switch ($variables['base_plugin_id']) {
case 'local_actions_block':
if (isset($variables['content']['entity.amp_metadata.add_form']) && $variables['content']['entity.amp_metadata.add_form']) {
$variables['content']['entity.amp_metadata.add_form']['#cache']['tags'][] = 'amp_types';
$message = '';
$has_no_amp_types = empty(\Drupal::service('amp.entity_type')
->getAmpEnabledTypes());
$has_global_metadata = \Drupal::service('amp.metadata')
->ampMetadataHasGlobal();
$all_types_have_metadata = empty(\Drupal::service('amp.metadata')
->getAmpNodeTypesWithoutMetadataSettings());
if ($has_no_amp_types) {
$message = t('No content types have AMP enabled. Please do so before adding AMP Metadata.');
}
else {
$message = t('All available global and content type overrides have been added. Please edit existing settings below.');
}
if ($has_no_amp_types || $has_global_metadata && $all_types_have_metadata) {
$variables['content']['entity.amp_metadata.add_form'] = [
'#markup' => '<p><strong>' . $message . '</strong></p>',
'addmetadata' => [
'#theme_wrappers' => [
'container' => [
'#attributes' => [
'class' => 'hidden',
],
],
],
'addlink' => $variables['content']['entity.amp_metadata.add_form'],
],
];
}
}
}
}