Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 25 |
ImageStyleFormBase | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 25 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
form | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 16 |
|||
save | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\image\Form\ImageStyleFormBase. | |
*/ | |
namespace Drupal\image\Form; | |
use Drupal\Core\Entity\EntityForm; | |
use Drupal\Core\Entity\EntityStorageInterface; | |
use Drupal\Core\Form\FormStateInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Base form for image style add and edit forms. | |
*/ | |
abstract class ImageStyleFormBase extends EntityForm { | |
/** | |
* The entity being used by this form. | |
* | |
* @var \Drupal\image\ImageStyleInterface | |
*/ | |
protected $entity; | |
/** | |
* The image style entity storage. | |
* | |
* @var \Drupal\Core\Entity\EntityStorageInterface | |
*/ | |
protected $imageStyleStorage; | |
/** | |
* Constructs a base class for image style add and edit forms. | |
* | |
* @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage | |
* The image style entity storage. | |
*/ | |
public function __construct(EntityStorageInterface $image_style_storage) { | |
$this->imageStyleStorage = $image_style_storage; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container) { | |
return new static( | |
$container->get('entity.manager')->getStorage('image_style') | |
); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function form(array $form, FormStateInterface $form_state) { | |
$form['label'] = array( | |
'#type' => 'textfield', | |
'#title' => $this->t('Image style name'), | |
'#default_value' => $this->entity->label(), | |
'#required' => TRUE, | |
); | |
$form['name'] = array( | |
'#type' => 'machine_name', | |
'#machine_name' => array( | |
'exists' => array($this->imageStyleStorage, 'load'), | |
), | |
'#default_value' => $this->entity->id(), | |
'#required' => TRUE, | |
); | |
return parent::form($form, $form_state); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function save(array $form, FormStateInterface $form_state) { | |
parent::save($form, $form_state); | |
$form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); | |
} | |
} |