public function PhoneDonationBlock::build in Commerce Donate 8
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/ PhoneDonationBlock.php, line 93
Class
- PhoneDonationBlock
- Provides a Phone to Donate block.
Namespace
Drupal\commerce_donate\Plugin\BlockCode
public function build() {
$config = $this
->getConfiguration();
$markup = '';
if (!empty($config['intro'])) {
$intro = $config['intro'];
$markup .= '<p class="phone-donation__intro">' . $intro . '</p>';
}
if (!empty($config['main_number'])) {
$main = $config['main_number'];
$main_label = $config['main_number_label'];
$markup .= $this
->t('<p class="phone-donation__main">@main_label <a href="tel:@main" class="phone-donation__main-number phone-donation__number-link">@main</a></p>', [
'@main_label' => $main_label,
'@main' => $main,
]);
}
if (!empty($config['intl_number'])) {
$international = $config['intl_number'];
$international_label = $config['intl_number_label'];
$markup .= $this
->t('<p class="phone-donation__international">@international_label <a href="tel:@international" class="phone-donation__international-number phone-donation__number-link">@international</a></p>', [
'@international_label' => $international_label,
'@international' => $international,
]);
}
return [
'#markup' => $markup,
];
}