Skip to content
Snippets Groups Projects

imp: add operation, action link

Merged simon requested to merge imp-add-ticketmatic-service into 1.x
Compare and
9 files
+ 217
2
Preferences
File browser
Compare changes
+ 119
0
<?php
namespace Drupal\druplan_ticketmatic\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\druplan_ticketmatic\DruplanTicketmatic;
use Drupal\resource_planning\Entity\Event;
/**
* Provides a Druplan TicketMatic form.
*/
class EventTicketMaticForm extends FormBase {
/**
* The TicketMatic API.
*
* @var \Drupal\druplan_ticketmatic\DruplanTicketmatic
*/
protected $ticketmatic;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The event.
*
* @var \Drupal\resource_planning\Entity\Event
*/
protected $event;
/**
* Constructs a Drupal\druplan_ticketmatic\Form\EventTicketMaticForm object.
*/
public function __construct(DruplanTicketmatic $ticketmatic, EntityTypeManagerInterface $entity_type_manager) {
$this->ticketmatic = $ticketmatic;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('druplan_ticketmatic.default'),
$container->get('entity_type.manager'),
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'druplan_ticketmatic_event_ticket_matic';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Event $rp_event = NULL) {
if ($rp_event) {
$this->event = $rp_event;
}
$form['intro'] = [
'#markup' => $this->t('Are you sure you wish to create a TicketMatic event?'),
];
$view_builder = $this->entityTypeManager->getViewBuilder('rp_event');
$form['details'] = [
'#type' => 'details',
'#title' => $this->t('Event Details'),
'#open' => TRUE,
'details' => $view_builder->build(
$view_builder->view($this->event)
),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Send'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($this->event->get('ticketmatic_id')->value) {
$form_state->setErrorByName(
'actions',
$this->t('This event already has a ticketmatic ID')
);
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->ticketmatic->createEvent(
$this->event);
$this->messenger()->addStatus($this->t('The Event has been created.'));
}
}