public function AmpMetadataListBuilder::getLabelAndConfig in Accelerated Mobile Pages (AMP) 8
Renders the metada settings label plus its configuration.
Parameters
AmpMetadataInterface $entity: The metadata settings entity.
Return value
Render array for a table cell.
1 call to AmpMetadataListBuilder::getLabelAndConfig()
- AmpMetadataListBuilder::buildRow in src/
AmpMetadataListBuilder.php - Builds a row for an entity in the entity listing.
File
- src/
AmpMetadataListBuilder.php, line 121
Class
- AmpMetadataListBuilder
- Provides a listing of AMP Metadata entities.
Namespace
Drupal\ampCode
public function getLabelAndConfig(EntityInterface $entity) {
$prefix = '';
$label = '';
$has_settings = FALSE;
if ($entity
->id() != 'global') {
$prefix = '<div class="indentation"></div>';
$label = $this
->t('Settings for @type @overrides', [
'@type' => $entity
->label(),
'@overrides' => $this->ampMetadataInfo
->ampMetadataHasGlobal() ? 'overrides' : '',
]);
}
else {
$label = $this
->t('Settings for global metadata');
}
$details = [
'#type' => 'table',
'#title' => $label,
'#header' => [
'Setting',
'Data',
],
];
if (!empty($org_name = $entity
->getOrganizationName())) {
$details['organization_name']['label'] = [
'#markup' => '<strong>Organization name</strong>:',
];
$details['organization_name']['value'] = [
'#markup' => $org_name,
];
$has_settings = TRUE;
}
/** @var FileInterface $org_logo_file */
if (!empty($org_logo_fid = $entity
->getOrganizationLogoFid()) && !empty($org_logo_file = File::load($org_logo_fid))) {
$details['organization_logo']['label'] = [
'#markup' => '<strong>Organization logo file</strong>:',
];
$details['organization_logo']['value'] = [
'#markup' => $org_logo_file
->getFilename(),
];
$has_settings = TRUE;
}
/** @var ImageStyleInterface $org_logo_image_style */
if (!empty($org_logo_image_style_id = $entity
->getOrganizationLogoImageStyleId()) && !empty($org_logo_image_style = ImageStyle::load($org_logo_image_style_id))) {
$details['organization_logo_image_style']['label'] = [
'#markup' => '<strong>Organization logo image style</strong>:',
];
$details['organization_logo_image_style']['value'] = [
'#markup' => $org_logo_image_style
->getName(),
];
$has_settings = TRUE;
}
if (!empty($content_headline = $entity
->getContentHeadlineToken())) {
$details['content_headline']['label'] = [
'#markup' => '<strong>Content headline token</strong>:',
];
$details['content_headline']['value'] = [
'#markup' => $content_headline,
];
$has_settings = TRUE;
}
if (!empty($content_schema = $entity
->getContentSchemaType())) {
$details['content_schema_type']['label'] = [
'#markup' => '<strong>Content schema type</strong>:',
];
$details['content_schema_type']['value'] = [
'#markup' => $content_schema,
];
$has_settings = TRUE;
}
if (!empty($content_author = $entity
->getContentAuthorToken())) {
$details['content_author']['label'] = [
'#markup' => '<strong>Content author token</strong>:',
];
$details['content_author']['value'] = [
'#markup' => $content_author,
];
$has_settings = TRUE;
}
if (!empty($content_description = $entity
->getContentDescriptionToken())) {
$details['content_description']['label'] = [
'#markup' => '<strong>Content author token</strong>:',
];
$details['content_description']['value'] = [
'#markup' => $content_description,
];
$has_settings = TRUE;
}
if (!empty($content_image = $entity
->getContentImageToken())) {
$details['content_image']['label'] = [
'#markup' => '<strong>Content image token</strong>:',
];
$details['content_image']['value'] = [
'#markup' => $content_image,
];
$has_settings = TRUE;
}
/** @var ImageStyleInterface $content_image_style */
if (!empty($content_image_style_id = $entity
->getContentImageStyleId()) && !empty($content_image_style = ImageStyle::load($content_image_style_id))) {
$details['content_image_style']['label'] = [
'#markup' => '<strong>Content image style</strong>:',
];
$details['content_image_style']['value'] = [
'#markup' => $content_image_style
->getName(),
];
$has_settings = TRUE;
}
if (!$has_settings) {
$details = [
'#markup' => $this
->t('No settings for this metadata type.'),
];
}
return [
'data' => [
'#type' => 'details',
'#prefix' => $prefix,
'#title' => $entity
->label(),
'details' => $details,
],
];
}