Generate case entity. (Called CaseEntity because "Case" is reserved word)

This commit is contained in:
naomi
2018-04-12 15:32:24 +02:00
parent 6746b986db
commit c9cf33ac19
25 changed files with 1028 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
/**
* Provides a form for deleting Case entity entities.
*
* @ingroup zencrm_entities
*/
class CaseEntityDeleteForm extends ContentEntityDeleteForm {
}

View File

@ -0,0 +1,50 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for Case entity edit forms.
*
* @ingroup zencrm_entities
*/
class CaseEntityForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\zencrm_entities\Entity\CaseEntity */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Case entity.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Case entity.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.case_entity.canonical', ['case_entity' => $entity->id()]);
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class CaseEntitySettingsForm.
*
* @ingroup zencrm_entities
*/
class CaseEntitySettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'caseentity_settings';
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Empty implementation of the abstract submit class.
}
/**
* Defines the settings form for Case entity entities.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* Form definition array.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['caseentity_settings']['#markup'] = 'Settings form for Case entity entities. Manage field settings here.';
return $form;
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Builds the form to delete Case entity type entities.
*/
class CaseEntityTypeDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.case_entity_type.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label(),
]
)
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Class CaseEntityTypeForm.
*/
class CaseEntityTypeForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$case_entity_type = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $case_entity_type->label(),
'#description' => $this->t("Label for the Case entity type."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $case_entity_type->id(),
'#machine_name' => [
'exists' => '\Drupal\zencrm_entities\Entity\CaseEntityType::load',
],
'#disabled' => !$case_entity_type->isNew(),
];
/* You will need additional form elements for your custom properties. */
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$case_entity_type = $this->entity;
$status = $case_entity_type->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Case entity type.', [
'%label' => $case_entity_type->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Case entity type.', [
'%label' => $case_entity_type->label(),
]));
}
$form_state->setRedirectUrl($case_entity_type->toUrl('collection'));
}
}