I am writing a patch for a module that used an old beta or even alpha of webform for drupal 8.

There is a line WebformEntityReferenceItem::getEntityWebformFieldName($node); in the module that errors out saying getEntityWebformFieldName() does not exist and sure enough in Drupal\webform\Plugin\Field\FieldType\WebformEntityReferenceItem the method does not exist.

I checked an older release and the method was there at some point. I've been searching since yesterday but cannot find a workaround or even an answer as to why it was removed. Any ideas?


So I managed to get it working, but this certainly seems like the incorrect way to do it.


So it seems WebformEntityReferenceItem::getEntityWebformFieldName($node); just gets the webform on the webform node and then grabs its 'target_id' value.

$webform_field_name = WebformEntityReferenceItem::getEntityWebformFieldName($node);
$webform_id = $node->$webform_field_name->target_id;

What I posted in my edit, I do not believe is the correct solution, albeit it is now working. Any suggestions would be appreciated.

  • Run update.php, clear cache, should fix it
    – Clive
    Commented Jan 9, 2018 at 17:59
  • Sorry, I meant I am writing a patch to update the module. Not apply an update. I'll edit my post. @Clive
    – Ronnie
    Commented Jan 9, 2018 at 18:02
  • What is your final goal? Are you after the webform itself, or its submissions? You might want to take a look at drupal.stackexchange.com/questions/244574/… Commented Jan 9, 2018 at 18:45
  • @Neograph734 I needed the webform id when using webform node. WebformEntityReferenceItem::getEntityWebformFieldName(); doesn't appear to exist anymore as of webform 8-rc1. I want to know what to replace that with. I cannot find any mention of it being removed. The line in my edit seems to have fixed the module I am patching, but it seems hacky.
    – Ronnie
    Commented Jan 9, 2018 at 19:06

1 Answer 1


The WebformEntityReferenceItem::getEntityWebformFieldName() static method was not removed but it was refactored and moved to the 'webform.entity_reference_manager'service.

Here is an example of showing how to use the service.

/** @var \Drupal\webform\WebformEntityReferenceManagerInterface $entity_reference_manager */
$entity_reference_manager = \Drupal::service('webform.entity_reference_manager');
$field_name = $entity_reference_manager->getFieldName($node);

@see \Drupal\webform\WebformEntityReferenceManager

@see \Drupal\webform\WebformEntityReferenceManagerInterface

  • 1
    perfect, this is exactly what I was looking for. Thanks for all the work you've done for this module
    – Ronnie
    Commented Jan 9, 2018 at 22:52
  • I am trying to get this working and I am doing: WebformEntityReferenceManager::getFieldName($node);, but getting an error saying Error: Using $this when not in object contextwhere $node is of type Drupal\node\Entity\Node I must be calling this incorrectly but cant figure it out. If I call the method through the interface it says non static methods can be called statically. Any ideas?
    – Ronnie
    Commented Jan 10, 2018 at 23:41
  • 1
    I added a code example to my answer.
    – jrockowitz
    Commented Jan 22, 2018 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.