I am trying to create a WebformHandler, when adding the handler to a webform via the Webform GUI the error below is what is being displayed. I have search the build and the namespace is only been used once.

Can someone tell me why this is happening?

    FatalErrorException in PncWebformHandler.php line 0:Compile Error:
Cannot declare class    
    because the name is already in use

The plugin has the following file structure

enter image description here

info.yml has following,

name: PNC Webform Handler
description: Handles form submits, does something with them.
package: Custom
type: module
version: 1.0
core: 8.x

The plugin class has the following,


namespace Drupal\pnc_webform_handler\Plugin\WebformHandler;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\webformSubmissionInterface;

 * Download a webform handler.
 * @WebformHandler(
 *   id = "pnc_webform_handler",
 *   label = @Translation(" "),
 *   category = @Translation(" "),
 *   description = @Translation(" "),
 *   cardinality = \Drupal\webform\WebformHandlerInterface::CARDINALITY_UNLIMITED,
 *   results = \Drupal\webform\WebformHandlerInterface::RESULTS_PROCESSED,
 * )
class PncWebformHandler extends WebformHandlerBase {

   * {@inheritdoc}
  public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {

    $values = $webform_submission->getData();
    $post_url = $this->configuration['submission_url'];
    \Drupal::logger('pnc_webform_handler')->error('Web form url: @error', ['@error' => print_r($values, 1)]);
    //$client = new \Drupal::httpClient();
    // $response = $client->request('GET', 'https://<your_third_party_service_here>',
    //   'form_params' => [
    //      'first_name' => $webform_submission->getData('first_name')
    //   ]
    // );
    // $code = $response->getStatusCode();
    //if ($code >= 400 || $code === 0) {
    // Handle the error
    // }

    return true;


I am using a vagrant box https://github.com/beetboxvm/beetbox with php 7

Here is a link to my latest attempt

  • "Cannot declare class" is almost always a namespacing issue but I can't figure out what is wrong with your code. – jrockowitz Nov 11 '17 at 22:29

I've downloaded the archived source code you attached and it doesn't reflect what you've presented here. The code from your question is correct.

However, you wrongly defined the namespace (in the attached archive). Change:

namespace Drupal\pnc_webform_handler\src\Plugin\WebformHandler;


namespace Drupal\purencool_webform_access\Plugin\WebformHandler;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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