public function MobileNumberVerifiedFormatter::viewElements in Mobile Number 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Field/FieldFormatter/MobileNumberVerifiedFormatter.php \Drupal\mobile_number\Plugin\Field\FieldFormatter\MobileNumberVerifiedFormatter::viewElements()
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ MobileNumberVerifiedFormatter.php, line 24
Class
- MobileNumberVerifiedFormatter
- Plugin implementation of the 'mobile_number_verified' formatter.
Namespace
Drupal\mobile_number\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
/** @var \Drupal\mobile_number\MobileNumberUtilInterface $util */
$util = \Drupal::service('mobile_number.util');
$element = [];
foreach ($items as $delta => $item) {
/** @var \Drupal\mobile_number\Plugin\Field\FieldType\MobileNumberItem $item */
if ($mobile_number = $util
->getMobileNumber($item
->getValue()['value'], NULL, [])) {
$element[$delta] = [
'#markup' => '<span class="verified-status' . (!empty($item->verified) ? ' verified' : '') . '">' . (!empty($item->verified) ? (string) t('Verified') : (string) t('Not verified')) . '</span>',
];
}
}
return $element;
}