trait LabeledFormTrait in Extensible BBCode 8.3
Same name and namespace in other branches
- 4.0.x src/Form/LabeledFormTrait.php \Drupal\xbbcode\Form\LabeledFormTrait
Helper function for adding label fields to an entity form.
@package Drupal\xbbcode\Form
Hierarchy
- trait \Drupal\xbbcode\Form\LabeledFormTrait uses StringTranslationTrait
File
- src/
Form/ LabeledFormTrait.php, line 13
Namespace
Drupal\xbbcode\FormView source
trait LabeledFormTrait {
use StringTranslationTrait;
/**
* Gets the form entity.
*
* The form entity which has been used for populating form element defaults.
*
* Redeclared here because PHP traits cannot implement interfaces.
*
* @return \Drupal\Core\Entity\EntityInterface
* The current form entity.
*
* @see \Drupal\Core\Entity\EntityFormInterface::getEntity()
*/
public abstract function getEntity() : EntityInterface;
/**
* Add label fields to the form array.
*
* @param array $form
* Form array.
*
* @return array
* Form array.
*/
public function addLabelFields(array $form) : array {
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#default_value' => $this
->getEntity()
->label(),
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -30,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $this
->getEntity()
->id(),
'#maxlength' => 255,
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'source' => [
'label',
],
],
'#disabled' => !$this
->getEntity()
->isNew(),
'#weight' => -20,
];
return $form;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LabeledFormTrait:: |
public | function | Add label fields to the form array. | |
LabeledFormTrait:: |
abstract public | function | Gets the form entity. | 2 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |