function _rac_get_entity_reference_role_fields in Role Access Control 8
Same name and namespace in other branches
- 8.2 rac.module \_rac_get_entity_reference_role_fields()
Get list of role reference fields for an entity bundle.
Retrieves a list of field names of Entity reference fields with type role.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $type: Entity type to retrieve fields of.
string $bundle: Name of Entity Bundle to filter fields by. Defaults to Entity type id if none provided.
Return value
array List of field name of role reference fields on the bundle. If there are no fields, the array is empty.
3 calls to _rac_get_entity_reference_role_fields()
- rac_fca_field_widget_field_collection_embed_form_alter in contrib/
rac_fca/ rac_fca.module - Implements hook_field_widget_WIDGET_TYPE_form_alter().
- rac_na_form_node_form_alter in contrib/
rac_na/ rac_na.module - Implements hook_form_FORM_ID_alter().
- _rac_get_entity_reference_roles in ./
rac.module - Get list of roles refrenced by $entity and cache it.
File
- ./
rac.module, line 43 - Module providing role access relations.
Code
function _rac_get_entity_reference_role_fields(EntityTypeInterface $type, $bundle = NULL) {
$bundle_fields =& drupal_static(__FUNCTION__);
if (!$type
->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
return [];
}
$type_id = $type
->id();
if ($bundle === NULL) {
$bundle = $type_id;
}
if (!isset($bundle_fields[$type_id]) || !isset($bundle_fields[$type_id][$bundle])) {
$bundle_fields[$type_id][$bundle] = [];
// Get fields of bundle.
$fields = \Drupal::entityManager()
->getFieldDefinitions($type_id, $bundle);
// Filter fields on bundle to only role references.
foreach ($fields as $field) {
$field_type = method_exists($field, 'getType') ? $field
->getType() : NULL;
$target_type = method_exists($field, 'getSetting') ? $field
->getSetting('target_type') : NULL;
if ($field_type === 'entity_reference' && $target_type === 'user_role') {
$field_storage = $field
->getFieldStorageDefinition();
if ($field_storage
->getThirdPartySetting("rac", "enabled", FALSE)) {
$bundle_fields[$type_id][$bundle][] = $field
->getName();
}
}
}
}
return isset($bundle_fields[$type_id][$bundle]) ? $bundle_fields[$type_id][$bundle] : FALSE;
}