public function OgMembership::getFieldValue in Organic groups 8
Gets the value of a specific property of a field.
Only the first delta can be accessed with this method.
@todo Remove this once issue #2580551 is fixed.
Parameters
string $field_name: The name of the field.
string $property: The field property, "value" for many field types.
Return value
mixed The value.
See also
https://www.drupal.org/project/drupal/issues/2580551
7 calls to OgMembership::getFieldValue()
- OgMembership::getCreatedTime in src/
Entity/ OgMembership.php - Gets the membership creation timestamp.
- OgMembership::getGroupBundle in src/
Entity/ OgMembership.php - Gets the group entity bundle.
- OgMembership::getGroupEntityType in src/
Entity/ OgMembership.php - Gets the group entity type.
- OgMembership::getGroupId in src/
Entity/ OgMembership.php - Gets the group entity ID.
- OgMembership::getOwnerId in src/
Entity/ OgMembership.php - Returns the entity owner's user ID.
File
- src/
Entity/ OgMembership.php, line 606
Class
- OgMembership
- The membership entity that connects a group and a user.
Namespace
Drupal\og\EntityCode
public function getFieldValue($field_name, $property) {
// Attempt to get the value from the values directly if the field is not
// initialized yet.
if (!isset($this->fields[$field_name])) {
$field_values = NULL;
if (isset($this->values[$field_name][$this->activeLangcode])) {
$field_values = $this->values[$field_name][$this->activeLangcode];
}
elseif (isset($this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT])) {
$field_values = $this->values[$field_name][LanguageInterface::LANGCODE_DEFAULT];
}
if ($field_values !== NULL) {
// If there are field values, try to get the property value.
// Configurable/Multi-value fields are stored differently, try accessing
// with delta and property first, then without delta and last, if the
// value is a scalar, just return that.
if (isset($field_values[0][$property]) && is_array($field_values[0])) {
return $field_values[0][$property];
}
elseif (isset($field_values[$property]) && is_array($field_values)) {
return $field_values[$property];
}
elseif (!is_array($field_values)) {
return $field_values;
}
}
}
// Fall back to access the property through the field object.
return $this
->get($field_name)->{$property};
}