public function CopyrightFooter::build in Copyright Footer 8
Same name and namespace in other branches
- 2.x src/Plugin/Block/CopyrightFooter.php \Drupal\copyright_footer\Plugin\Block\CopyrightFooter::build()
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ CopyrightFooter.php, line 116 - Contains \Drupal\copyright_footer\Plugin\Block\CopyrightFooter.
Class
- CopyrightFooter
- Copyright Footer module for Block.
Namespace
Drupal\copyright_footer\Plugin\BlockCode
public function build() : array {
$date = new \DateTime();
// From $year_to_date to Present.
$year_to_date = empty($this->configuration['year_to_date']) ? $date
->format('Y') : $this->configuration['year_to_date'];
// Organization.
$organization = $this->configuration['organization_name'];
// Organization w/ URL.
if (!empty($organization) && !empty($this->configuration['organization_url'])) {
$url = Url::fromUri($this->configuration['organization_url']);
$organization = Link::fromTextAndUrl($this->configuration['organization_name'], $url)
->toString();
}
// Version.
$version = $this->configuration['version'];
if (!empty($version)) {
// Version only.
$version = $this
->t('ver.@version', [
'@version' => $version,
]);
// Version w/ URL.
if ($this->configuration['version_url']) {
$url = Url::fromUri($this->configuration['version_url']);
$version = $this
->t('ver.@version', [
'@version' => Link::fromTextAndUrl($this->configuration['version'], $url)
->toString(),
]);
}
}
$year = $date
->format('Y');
return empty($this->configuration['year_origin']) || "{$this->configuration['year_origin']}" === $year ? [
'#type' => 'markup',
'#markup' => $this
->t('Copyright © @year @organization @version', [
'@year' => $year,
'@organization' => $organization,
'@version' => $version,
]),
] : [
'#type' => 'markup',
'#markup' => $this
->t('Copyright © @year_origin-@year_to_date @organization @version', [
'@year_origin' => $this->configuration['year_origin'],
'@year_to_date' => $year_to_date,
'@organization' => $organization,
'@version' => $version,
]),
];
}