MobileNumberVerifiedFormatter.php in Mobile Number 8
File
src/Plugin/Field/FieldFormatter/MobileNumberVerifiedFormatter.php
View source
<?php
namespace Drupal\mobile_number\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class MobileNumberVerifiedFormatter extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$util = \Drupal::service('mobile_number.util');
$element = [];
foreach ($items as $delta => $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;
}
}