function comment_alter_get_alterable_fields in Comment Alter 8
Same name and namespace in other branches
- 7 comment_alter.module \comment_alter_get_alterable_fields()
Returns the comment alterable fields for an entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity object for the parent entity.
Return value
array An array of comment alterable fields on parent entity.
3 calls to comment_alter_get_alterable_fields()
- comment_alter_entity_extra_field_info in ./
comment_alter.module - Implements hook_entity_extra_field_info().
- comment_alter_form_comment_form_alter in ./
comment_alter.module - Implements hook_form_BASE_FORM_ID_alter().
- comment_alter_get_changed_fields in ./
comment_alter.module - Returns a table showing the differences committed with a particular comment.
File
- ./
comment_alter.module, line 87 - Allows to alter entities from comment form.
Code
function comment_alter_get_alterable_fields($entity_type, $bundle) {
$cid = 'comment_alter_fields:' . $entity_type . ':' . $bundle;
$comment_alter_fields =& drupal_static(__FUNCTION__);
if (!isset($comment_alter_fields[$entity_type][$bundle])) {
if ($cache = \Drupal::cache()
->get($cid)) {
$comment_alter_fields[$entity_type][$bundle] = $cache->data;
}
else {
$field_definitions = \Drupal::entityManager()
->getFieldDefinitions($entity_type, $bundle);
foreach ($field_definitions as $field_name => $field_item) {
// Check if we are dealing with an actual field. The
// getThirdPartySetting method is available only for an actual field.
if (is_a($field_item, 'Drupal\\field\\Entity\\FieldConfig') && $field_item
->getThirdPartySetting('comment_alter', 'comment_alter_enabled', FALSE)) {
$comment_alter_fields[$entity_type][$bundle][$field_name] = $field_name;
}
}
if (!isset($comment_alter_fields[$entity_type][$bundle])) {
$comment_alter_fields[$entity_type][$bundle] = [];
}
\Drupal::cache()
->set($cid, $comment_alter_fields[$entity_type][$bundle]);
}
}
return $comment_alter_fields[$entity_type][$bundle];
}