Browse Source

remove leftover BundleFormAlter code

8.x-1.x
Peter Lindstrom 6 years ago
parent
commit
29249a61d0
  1. 12
      reserve.module
  2. 113
      src/BundleFormAlter.php

12
reserve.module

@ -12,7 +12,6 @@ use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\reserve\BundleFormAlter;
define ('RESERVE_SAVE_CONFIRMATION_MSG', t('Configuration settings have been saved'));
define ('RESERVE_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values'));
@ -54,17 +53,6 @@ function reserve_help($route_name, RouteMatchInterface $route_match) {
}
}
/**
* Implements hook_form_alter().
*/
function reserve_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if ($form_state->getFormObject() instanceof BundleEntityFormBase) {
(new BundleFormAlter($form_state->getFormObject()->getEntity()))
->formAlter($form, $form_state);
}
return;
}
/**
* Implements hook_entity_insert().
*/

113
src/BundleFormAlter.php

@ -1,113 +0,0 @@
<?php
namespace Drupal\reserve;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
/**
* Helper for reserve_form_alter().
*/
class BundleFormAlter {
/**
* Entity type definition.
*
* @var \Drupal\Core\Entity\ContentEntityTypeInterface
*/
protected $definition;
/**
* The entity bundle.
*
* @var string
*/
protected $bundle;
/**
* The bundle label.
*
* @var string
*/
protected $bundleLabel;
/**
* The entity type ID.
*
* @var string
*/
protected $entityTypeId;
/**
* The form entity which has been used for populating form element defaults.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $entity;
/**
* Construct a BundleFormAlter object.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*/
public function __construct(EntityInterface $entity) {
$this->entity = $entity;
}
/**
* This is a helper for og_ui_form_alter().
*
* @param array $form
* The form variable.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
public function formAlter(array &$form, FormStateInterface $form_state) {
$this->prepare($form, $form_state);
$this->addReserveCategories($form, $form_state);
}
/**
* Prepares object properties and adds the og details element.
*
* @param array $form
* The form variable.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
protected function prepare(array &$form, FormStateInterface $form_state) {
// Example: article.
$this->bundle = $this->entity->id();
// Example: Article.
$this->bundleLabel = Unicode::lcfirst($this->entity->label());
$this->definition = $this->entity->getEntityType();
// Example: node.
$this->entityTypeId = $this->definition->getBundleOf();
$form['reserve'] = [
'#type' => 'details',
'#title' => t('Reserve'),
'#collapsible' => TRUE,
'#group' => 'additional_settings',
'#description' => t('If any Reserve Categories are selected here; this bundle will be reservable.'),
];
}
/**
* Adds the "is group?" checkbox.
*/
protected function addReserveCategories(array &$form, FormStateInterface $form_state) {
$options = array('big', 'small');
$form['reserve']['reserve_categories'] = [
'#type' => 'checkboxes',
'#title' => t('Categories'),
'#options' => array_combine($options, $options),
//'#default_value' => Og::isGroup($this->entityTypeId, $this->bundle),
];
}
}
Loading…
Cancel
Save