public function OgGroupAudienceHelper::getAllGroupAudienceFields in Organic groups 8
Returns all the group audience fields of a certain bundle.
Parameters
string $group_content_entity_type_id: The entity type ID of the group content for which to return audience fields.
string $group_content_bundle_id: The bundle name of the group content for which to return audience fields.
string $group_entity_type_id: Filter list to only include fields referencing a specific group type. If omitted, all fields will be returned.
string $group_bundle_id: Filter list to only include fields referencing a specific group bundle. Fields that do not specify any bundle restrictions at all are also included. If omitted, the results will not be filtered by group bundle.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of field definitions, keyed by field name; Or an empty array if none found.
Overrides OgGroupAudienceHelperInterface::getAllGroupAudienceFields
1 call to OgGroupAudienceHelper::getAllGroupAudienceFields()
- OgGroupAudienceHelper::hasGroupAudienceField in src/
OgGroupAudienceHelper.php - Returns whether the given entity bundle has a group audience field.
File
- src/
OgGroupAudienceHelper.php, line 61
Class
- OgGroupAudienceHelper
- OG audience field helper methods.
Namespace
Drupal\ogCode
public function getAllGroupAudienceFields($group_content_entity_type_id, $group_content_bundle_id, $group_entity_type_id = NULL, $group_bundle_id = NULL) {
$return = [];
$entity_type = $this->entityTypeManager
->getDefinition($group_content_entity_type_id);
if (!$entity_type
->entityClassImplements(FieldableEntityInterface::class)) {
// This entity type is not fieldable.
return [];
}
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($group_content_entity_type_id, $group_content_bundle_id);
foreach ($field_definitions as $field_definition) {
if (!$this
->isGroupAudienceField($field_definition)) {
// Not a group audience field.
continue;
}
$target_type = $field_definition
->getFieldStorageDefinition()
->getSetting('target_type');
if (isset($group_entity_type_id) && $target_type != $group_entity_type_id) {
// Field doesn't reference this group type.
continue;
}
$handler_settings = $field_definition
->getSetting('handler_settings');
if (isset($group_bundle_id) && !empty($handler_settings['target_bundles']) && !in_array($group_bundle_id, $handler_settings['target_bundles'])) {
continue;
}
$field_name = $field_definition
->getName();
$return[$field_name] = $field_definition;
}
return $return;
}