You are here

public function MobileNumberItem::isVerified in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldType/MobileNumberItem.php \Drupal\mobile_number\Plugin\Field\FieldType\MobileNumberItem::isVerified()

Is the item's mobile number verified in the field's saved values or current session.

Return value

bool TRUE if verified, else FALSE.

2 calls to MobileNumberItem::isVerified()
MobileNumberItem::isUnique in src/Plugin/Field/FieldType/MobileNumberItem.php
Is mobile number unique within the entity/field. Will check verified numbers, only if specificed.
MobileNumberItem::verify in src/Plugin/Field/FieldType/MobileNumberItem.php
Performs verification, assuming verification token and code were set. Adds to flood if failed. Will not attempt to verify if number is already verified.

File

src/Plugin/Field/FieldType/MobileNumberItem.php, line 424

Class

MobileNumberItem
Plugin implementation of the 'mobile_number' field type.

Namespace

Drupal\mobile_number\Plugin\Field\FieldType

Code

public function isVerified() {

  /** @var \Drupal\mobile_number\MobileNumberUtilInterface $util */
  $util = \Drupal::service('mobile_number.util');
  $input = $this
    ->getValue();
  $field_name = $this
    ->getFieldDefinition()
    ->getName();
  $field_label = $this
    ->getFieldDefinition()
    ->getLabel();

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $this
    ->getEntity();
  $entity_type = $entity
    ->getEntityType()
    ->getSingularLabel();
  $entity_type_id = $entity
    ->getEntityTypeId();
  $id_key = $entity
    ->getEntityType()
    ->getKey('id');
  $mobile_number = $this
    ->getMobileNumber();
  if (!$mobile_number) {
    return FALSE;
  }
  $verified = (bool) \Drupal::entityQuery($entity_type_id)
    ->condition($id_key, (int) $entity
    ->id())
    ->condition($field_name, $util
    ->getCallableNumber($mobile_number))
    ->range(0, 1)
    ->condition("{$field_name}.verified", "1")
    ->count()
    ->execute();
  $verified = $verified || $util
    ->isVerified($mobile_number);
  return $verified;
}