3

Currently trying to port over a Contrib module and learn the new Drupal 8 architecture.

A google search revealed a possible issue related to this.

The cause could be that there's an underscore in the file name which violates psr-0 naming standards. Looks like i had that before and have renamed it just now and still have that issue after clearing the cache.

What would likely be the cause of the following error?

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "\drupal\form_example\forms\formexampleformone". in Symfony\Component\DependencyInjection\Container->get() (line 304 of /home/chris/workspace/d8/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Container.php).

The error occurs when i visit /examples/form_example/tutorial/1

form_example.routing.yml

form_example:
  path: 'examples/form_example'
  defaults:
    # _form: '\Drupal\form_example\Forms\FormExampleForm'
    _content: '\Drupal\form_example\Controller\FormExampleController::description'
  requirements:
    _access: 'TRUE'
form_example_tutorial_1:
  path: 'examples/form_example/tutorial/1'
  defaults:
    _form: '\Drupal\form_example\Forms\FormExampleForm'
  requirements:
    _access: 'TRUE'

form_example.module

<?php
function form_example_menu() {
//   $items = array();
//   $items['examples/form_example'] = array(
//     'title' => 'Form Example',
//     'route_name' => 'form_example',
//     'access callback' => TRUE,
//     'expanded' => TRUE,
//   );
  $items['examples/form_example/tutorial'] = array(
    'title' => 'Form Tutorial',
    // 'page callback' => 'drupal_get_form',
    'route_name' => array('form_example_tutorial'),
    'access callback' => TRUE,
    'description' => 'A set of ten tutorials',
    // 'file' => 'form_example_tutorial.inc',
    // 'type' => MENU_NORMAL_ITEM,
  );
  $items['examples/form_example/tutorial/1'] = array(
    'title' => '#1',
    // 'page callback' => 'drupal_get_form',
    'route_name' => array('form_example_tutorial_1'),
    'access callback' => TRUE,
    'description' => 'Tutorial 1: Simplest form',
    // 'type' => MENU_DEFAULT_LOCAL_TASK,
    // 'file' => 'form_example_tutorial.inc',
  );
  return $items;
}

/lib/Drupal/form_example/Forms/FormExampleForm.php

<?php
/**
 * @file
 * Contains \Drupal\form_example\Form\FormExampleForm
 */
namespace Drupal\form_example;

use Drupal\Core\Form\FormInterface;

class FormExampleForm extends FormBase {
// form...
}
2
  • Can you provide your routing.yml file?
    – Berdir
    Oct 16, 2013 at 5:39
  • Sure thing updated @Berdir
    – chrisjlee
    Oct 16, 2013 at 12:27

1 Answer 1

2

Looks like the namespace defined in your class file does not match the one you put into the resource, there's a "Form" sub-namespace missing.

Also make sure that the class is placed in the right folder.

The reason for that error is apparently that for some reason, the specified class can't be found, so apparently the router then falls back to the service. So the _ thing is just one possible reason.

Also, there are some errors in your hook_menu(), route_name is a string, access callback can be removed and you still need the first entry for now so that you have a menu link to it.

1

Your Answer

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

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