Newer
Older
Dries Buytaert
committed
<?php
/**
* @file
* Contains \Drupal\block_content\BlockContentTypeForm.
Dries Buytaert
committed
*/
namespace Drupal\block_content;
Dries Buytaert
committed
Alex Pott
committed
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeInterface;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ContentLanguageSettings;
Dries Buytaert
committed
/**
Alex Pott
committed
* Base form for category edit forms.
Dries Buytaert
committed
*/
class BlockContentTypeForm extends EntityForm {
Dries Buytaert
committed
/**
Dries Buytaert
committed
* {@inheritdoc}
Dries Buytaert
committed
*/
Dries Buytaert
committed
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
Dries Buytaert
committed
/* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
$block_type = $this->entity;
Dries Buytaert
committed
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#maxlength' => 255,
'#default_value' => $block_type->label(),
'#description' => t("Provide a label for this block type to help identify it in the administration pages."),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $block_type->id(),
'#machine_name' => array(
'exists' => '\Drupal\block_content\Entity\BlockContentType::load',
Dries Buytaert
committed
),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
Dries Buytaert
committed
'#disabled' => !$block_type->isNew(),
);
$form['description'] = array(
'#type' => 'textarea',
'#default_value' => $block_type->getDescription(),
Dries Buytaert
committed
'#description' => t('Enter a description for this block type.'),
'#title' => t('Description'),
);
$form['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $block_type->shouldCreateNewRevision(),
Dries Buytaert
committed
'#description' => t('Create a new revision by default for this block type.')
);
if ($this->moduleHandler->moduleExists('language')) {
Dries Buytaert
committed
$form['language'] = array(
'#type' => 'details',
'#title' => t('Language settings'),
'#group' => 'additional_settings',
);
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
Dries Buytaert
committed
$form['language']['language_configuration'] = array(
'#type' => 'language_configuration',
'#entity_information' => array(
'entity_type' => 'block_content',
Dries Buytaert
committed
'bundle' => $block_type->id(),
),
'#default_value' => $language_configuration,
);
$form['#submit'][] = 'language_configuration_element_submit';
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* {@inheritdoc}
Dries Buytaert
committed
*/
Dries Buytaert
committed
public function save(array $form, FormStateInterface $form_state) {
$block_type = $this->entity;
Dries Buytaert
committed
$status = $block_type->save();
Angie Byron
committed
$edit_link = $this->entity->link($this->t('Edit'));
$logger = $this->logger('block_content');
Dries Buytaert
committed
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Custom block type %label has been updated.', array('%label' => $block_type->label())));
$logger->notice('Custom block type %label has been updated.', array('%label' => $block_type->label(), 'link' => $edit_link));
Dries Buytaert
committed
}
else {
block_content_add_body_field($block_type->id());
Dries Buytaert
committed
drupal_set_message(t('Custom block type %label has been added.', array('%label' => $block_type->label())));
$logger->notice('Custom block type %label has been added.', array('%label' => $block_type->label(), 'link' => $edit_link));
Dries Buytaert
committed
}
Alex Pott
committed
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));