2015-08-20 6 views
0

Я начинаю с Drupal 8, и до сих пор я был очень впечатлен всеми новыми функциями. Тем не менее, я пытался написать свою собственную сущность, и я бегу в проблему:У кого-либо еще есть проблемы с получением пользовательских обработчиков, чтобы вставлять объекты D8?

Это определение сущность:

<?php 

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 

namespace Drupal\entitytest\Entity; 

use Drupal\Core\Entity\EntityStorageInterface; 
use Drupal\Core\Field\BaseFieldDefinition; 
use Drupal\Core\Entity\ContentEntityBase; 
use Drupal\Core\Entity\EntityTypeInterface; 

/** 
* Defines the Candidate Entity 
* 
* @ingroup entitytest 
* 
* @ContentEntityType(
* id="entitytest_AuditionCandidate", 
* [email protected]("Candidate"), 
* base_table="candidate", 
*  
* handlers = { 
*  "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", 
*  "list_builder" = "Drupal\entitytest\Entity\Controller\CandidateListBuilder", 
*  "form" = { 
*  "add" = "Drupal\Core\Entity\ContentEntityForm", 
*  "edit" = "Drupal\Core\Entity\ContentEntityForm",  
*  "delete" = "Drupal\EntityTest\Form\CandidateDeleteForm", 
*  }, 
* }, 
* admin_permission="administer candidates", 
* entity_keys={ 
*  "id"="id", 
*  "label"="lastname", 
* }, 
* links = { 
*  "canonical" = "/AuditionCandidate/view/{entitytest_AuditionCandidate}", 
*  "edit-form" = "/AuditionCandidate/edit/{entitytest_AuditionCandidate}", 
* }, 
*) 
*/ 
class Candidate extends ContentEntityBase { 
    public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { 
    $fields['id'] = BaseFieldDefinition::create('integer') 
     ->setLabel(t('ID')) 
     ->setDescription(t('The ID of the Contact entity.')) 
     ->setReadOnly(TRUE); 

    $fields['lastname'] = BaseFieldDefinition::create('string') 
     ->setLabel(t('Last Name')) 
     ->setDescription(t('The name of the Contact entity.')) 
     ->setSettings(array(
     'default_value' => '', 
     'max_length' => 255, 
     'text_processing' => 0, 
    )) 
     ->setDisplayOptions('view', array(
     'label' => 'above', 
     'type' => 'string', 
     'weight' => -6, 
    )) 
     ->setDisplayOptions('form', array(
     'type' => 'string', 
     'weight' => -6, 
    )) 
     ->setDisplayConfigurable('form', TRUE) 
     ->setDisplayConfigurable('view', TRUE); 

    $fields['firstname'] = BaseFieldDefinition::create('string') 
     ->setLabel(t('First Name')) 
     ->setDescription(t('The name of the Contact entity.')) 
     ->setSettings(array(
     'default_value' => '', 
     'max_length' => 255, 
     'text_processing' => 0, 
    )) 
     ->setDisplayOptions('view', array(
     'label' => 'above', 
     'type' => 'string', 
     'weight' => -6, 
    )) 
     ->setDisplayOptions('form', array(
     'type' => 'string', 
     'weight' => -6, 
    )) 
     ->setDisplayConfigurable('form', TRUE) 
     ->setDisplayConfigurable('view', TRUE); 

    return $fields; 
    } 
} 

Так что я пытаюсь изменить Deleteform от этого лица. Я создал файл под /modules/custom/EntityTest/src/Form/CandidateFormDelete.php

Код в этом файле выглядит следующим образом:

<?php 
namespace Drupal\EntityTest\Form; 

use Drupal\Core\Entity\ContentEntityConfirmFormBase; 
use Drupal\Core\Form\FormStateInterface; 
use Drupal\Core\Url; 

class CandidateDeleteForm extends ContentEntityConfirmFormBase { 
    public function getQuestion() { 
    return $this->t('Are you sure?'); 
    } 

    public function getCancelUrl() { 
    return new Url('entity.entitytest_AuditionCandidate.collection'); 
    } 

    public function getConfirmText() { 
    return $this->t('Delete'); 

    } 
} 

Я также добавил маршрут для удаления формы :

entity.entitytest_AuditionCandidate.delete_form: 
    path: 'AuditionCandidate/delete/{entitytest_AuditionCandidate}' 
    defaults: 
     _entity_form: entitytest_AuditionCandidate.delete 
     _title: 'Delete Candidate' 
    requirements: 
     _permission: 'administer candidates' 

Но когда я пытаюсь открыть/AuditionCandidate/удалить/1 Я получаю следующее сообщение об ошибке:

Drupal \ Component \ Plugin \ Exception \ InvalidPluginDefinitionExceptio n: Тип сущности «entitytest_AuditionCandidate» не указал класс формы «удалить». в Drupal \ Core \ Entity \ EntityManager-> getFormObject() (строка 309 ядра/lib/Drupal/Core/Entity/EntityManager.php).

Это просто не имеет смысла, поскольку я определил класс для формы delete.

Любой, кто может видеть то, что мне не хватает? Возможно, это просто опечатка, но я смотрел на нее довольно долгое время, и я просто не могу понять.

Мэтт.

ответ

0

Drupal 8 реализует стандарт PSR-4 для автозагрузки пространства имен на основе пакетов. В этом случае имя вашего файла класса не соответствует имени используемого фактического класса. Имя файла также должно быть «CandidateDeleteForm.php» вместо «CandidateFormDelete»

Именно по этой причине вы получаете это исключение. Подробнее об этом предмете читайте: https://www.drupal.org/node/2156625