public function Profile::equalToProfile in Profile 8
Checks whether the other profile is equal to the current profile.
By default, profiles are compared using configurable fields only, which means that two profiles can be considered equal even if they are of different types, or belong to different users. Pass "type", and/or "uid" as $field_names to avoid this behavior.
Parameters
\Drupal\profile\Entity\ProfileInterface $profile: The other profile.
string[] $field_names: The names of fields to compare. If empty, all configurable fields will be compared.
Return value
bool TRUE if the two profiles are equal, FALSE otherwise.
Overrides ProfileInterface::equalToProfile
File
- src/
Entity/ Profile.php, line 203
Class
- Profile
- Defines the profile entity class.
Namespace
Drupal\profile\EntityCode
public function equalToProfile(ProfileInterface $profile, array $field_names = []) {
// Compare all configurable fields by default.
$field_names = $field_names ?: $this
->getConfigurableFieldNames($profile);
foreach ($field_names as $field_name) {
$profile_field_item_list = $profile
->get($field_name);
if (!$this
->hasField($field_name) || !$this
->get($field_name)
->equals($profile_field_item_list)) {
return FALSE;
}
}
return TRUE;
}