function disable_field_get_entity_data in Disable Field 8
Returns data about entity by form state.
2 calls to disable_field_get_entity_data()
- disable_field_form_alter in ./
disable_field.module - Implements hook_form_alter().
- disable_field_form_fill_value in ./
disable_field.module - This functions fills default value for fields which are disabled, to avoid problem with saving invalid data.
File
- ./
disable_field.module, line 194
Code
function disable_field_get_entity_data($form_state) {
$form_entity_type_id = FALSE;
// Get Entity type ID.
if ($callback_object = $form_state
->getBuildInfo()['callback_object']) {
if (method_exists($callback_object, 'getEntity')) {
$form_entity_type_id = $callback_object
->getEntity()
->getEntityTypeId();
}
}
$bundle = FALSE;
$operation = FALSE;
// Get bundle and page operation(add/edit).
if ($form_object = $form_state
->getFormObject()) {
// If it's form of the content entity.
if ($form_object instanceof Drupal\Core\Entity\ContentEntityForm) {
$bundle = $form_object
->getEntity()
->bundle();
if ($entity = $form_object
->getEntity()) {
$operation = $entity
->id() ? 'edit' : 'add';
}
}
}
return [
$form_entity_type_id,
$bundle,
$operation,
];
}