Added activity entity

This commit is contained in:
naomi
2018-04-14 12:26:09 +02:00
parent 74e98818ba
commit 484fb5a119
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 Activity entities.
*
* @ingroup zencrm_entities
*/
class ActivityDeleteForm 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 Activity edit forms.
*
* @ingroup zencrm_entities
*/
class ActivityForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\zencrm_entities\Entity\Activity */
$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 Activity.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Activity.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.activity.canonical', ['activity' => $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 ActivitySettingsForm.
*
* @ingroup zencrm_entities
*/
class ActivitySettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'activity_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 Activity 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['activity_settings']['#markup'] = 'Settings form for Activity 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 Activity type entities.
*/
class ActivityTypeDeleteForm 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.activity_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 ActivityTypeForm.
*/
class ActivityTypeForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$activity_type = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $activity_type->label(),
'#description' => $this->t("Label for the Activity type."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $activity_type->id(),
'#machine_name' => [
'exists' => '\Drupal\zencrm_entities\Entity\ActivityType::load',
],
'#disabled' => !$activity_type->isNew(),
];
/* You will need additional form elements for your custom properties. */
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$activity_type = $this->entity;
$status = $activity_type->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Activity type.', [
'%label' => $activity_type->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Activity type.', [
'%label' => $activity_type->label(),
]));
}
$form_state->setRedirectUrl($activity_type->toUrl('collection'));
}
}