You are here

public function Subscriber::getUserSharedFields in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::getUserSharedFields()
  2. 3.x src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::getUserSharedFields()

Identifies configurable fields shared with a user.

Parameters

\Drupal\user\UserInterface $user: The user to match fields against.

Return value

string[] An indexed array of the names of each field for which there is also a field on the given user with the same name and type.

Overrides SubscriberInterface::getUserSharedFields

2 calls to Subscriber::getUserSharedFields()
Subscriber::postCreate in src/Entity/Subscriber.php
Acts on a created entity before hooks are invoked.
Subscriber::postSave in src/Entity/Subscriber.php
Acts on a saved entity before the insert or update hook is invoked.

File

src/Entity/Subscriber.php, line 320

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

public function getUserSharedFields(UserInterface $user) {
  $field_names = array();

  // Find any fields sharing name and type.
  foreach ($this
    ->getFieldDefinitions() as $field_definition) {

    /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
    $field_name = $field_definition
      ->getName();
    $user_field = $user
      ->getFieldDefinition($field_name);
    if ($field_definition
      ->getTargetBundle() && isset($user_field) && $user_field
      ->getType() == $field_definition
      ->getType()) {
      $field_names[] = $field_name;
    }
  }
  return $field_names;
}