Added Event entity type.
This commit is contained in:
51
src/Form/OCEventDeleteForm.php
Normal file
51
src/Form/OCEventDeleteForm.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Builds the form to delete Event entities.
|
||||
*/
|
||||
class OCEventDeleteForm 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.oc_event.collection');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->entity->delete();
|
||||
|
||||
$this->messenger()->addMessage(
|
||||
$this->t('content @type: deleted @label.', [
|
||||
'@type' => $this->entity->bundle(),
|
||||
'@label' => $this->entity->label(),
|
||||
])
|
||||
);
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
}
|
65
src/Form/OCEventForm.php
Normal file
65
src/Form/OCEventForm.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCEventForm.
|
||||
*/
|
||||
class OCEventForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$oc_event = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $oc_event->label(),
|
||||
'#description' => $this->t("Label for the Event."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $oc_event->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\opencase\Entity\OCEvent::load',
|
||||
],
|
||||
'#disabled' => !$oc_event->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$oc_event = $this->entity;
|
||||
$status = $oc_event->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
$this->messenger()->addMessage($this->t('Created the %label Event.', [
|
||||
'%label' => $oc_event->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->messenger()->addMessage($this->t('Saved the %label Event.', [
|
||||
'%label' => $oc_event->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($oc_event->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
26
src/OCEventHtmlRouteProvider.php
Normal file
26
src/OCEventHtmlRouteProvider.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
|
||||
/**
|
||||
* Provides routes for Event entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCEventHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
32
src/OCEventListBuilder.php
Normal file
32
src/OCEventListBuilder.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Event entities.
|
||||
*/
|
||||
class OCEventListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Event');
|
||||
$header['id'] = $this->t('Machine name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $entity->label();
|
||||
$row['id'] = $entity->id();
|
||||
// You probably want a few more properties here...
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
55
src/Plugin/Derivative/AddEventsMenuLink.php
Normal file
55
src/Plugin/Derivative/AddEventsMenuLink.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase\Plugin\Derivative;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Derivative class that provides the menu links adding various types of events
|
||||
*/
|
||||
class AddEventsMenuLink extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
/**
|
||||
* @var EntityTypeManagerInterface $entityTypeManager.
|
||||
*/
|
||||
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Creates a AddEventsMenuLink instance.
|
||||
*
|
||||
* @param $base_plugin_id
|
||||
* @param EntityTypeManagerInterface $entity_type_manager
|
||||
*/
|
||||
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$base_plugin_id,
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$links = [];
|
||||
$eventTypes = $this->entityTypeManager->getStorage('oc_event_type')->loadMultiple();
|
||||
foreach ($eventTypes as $id => $eventType) {
|
||||
$links[$id] = [
|
||||
'title' => "Add ". $eventType->label() . " Event",
|
||||
'route_name' => "entity.oc_event.add_form",
|
||||
'route_parameters' => ['oc_event_type' => $eventType->id()]
|
||||
] + $base_plugin_definition;
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
}
|
6
src/Plugin/Menu/AddEventsMenuLink.php
Normal file
6
src/Plugin/Menu/AddEventsMenuLink.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Drupal\opencase\Plugin\Menu;
|
||||
|
||||
use Drupal\Core\Menu\MenuLinkDefault;
|
||||
|
||||
class AddEventsMenuLink extends MenuLinkDefault {}
|
Reference in New Issue
Block a user