Skip to content
Snippets Groups Projects

Issue #3510517: Call to Undefined Method.

Merged Dhruv Mittal requested to merge issue/wsdata-3510517:3510517-call-to-undefined into 3.0.x
@@ -7,10 +7,12 @@
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Field\FieldConfigInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_ui\FieldUI;
use Drupal\wsdata_field\Entity\WSFieldConfig;
@@ -124,19 +126,21 @@ function wsdata_field_entity_load(array $entities, $entity_type_id) {
*/
function wsdata_field_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ('node_delete_multiple_confirm_form' !== $form_id && (preg_match('/^node_(.*)_edit_form/', $form_id) || preg_match('/^node_(.*)_form/', $form_id))) {
$entity = $form_state->getFormObject()->getEntity();
if ($entity->getEntityTypeId() == 'node') {
$fields = $entity->getFieldDefinitions();
foreach ($fields as $field) {
// Get the fields storage definitions.
$field_storage = $field->getFieldStorageDefinition();
// Check if it has the custom storage flag set to true.
if ($field_storage->hasCustomStorage()) {
// Check to make sure the object is of type FieldStorageConfig.
if (is_a($field_storage, 'Drupal\field\Entity\FieldStorageConfig')) {
$form_object = $form_state->getFormObject();
// Ensure the form object has a getEntity method before calling it.
if ($form_object instanceof EntityFormInterface) {
$entity = $form_object->getEntity();
if ($entity instanceof ContentEntityInterface) {
$fields = $entity->getFieldDefinitions();
foreach ($fields as $field) {
// Get the fields storage definitions.
$field_storage = $field->getFieldStorageDefinition();
// Check if custom storage flag set to true and
// the field storage object has correct class.
if ($field_storage->hasCustomStorage() && $field_storage instanceof FieldStorageConfig) {
// Fetch the wsfield config entity.
$wsfield_config = \Drupal::service('entity_type.manager')->getStorage('wsfield_config')->load($field_storage->get('field_name'));
if ($wsfield_config != NULL) {
if ($wsfield_config !== NULL) {
// Make the field hidden by adding a class.
$form[$field_storage->get('field_name')]['#attributes']['class'][] = 'hidden';
}
Loading