MarkupItem.php in Markup 8
File
src/Plugin/Field/FieldType/MarkupItem.php
View source
<?php
namespace Drupal\markup\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
class MarkupItem extends FieldItemBase {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'markup' => [
'type' => 'varchar',
'length' => 255,
],
],
];
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['markup'] = DataDefinition::create('string')
->setLabel(t('Markup'));
return $properties;
}
public static function defaultFieldSettings() {
return [
'markup' => [
'value' => '',
'format' => '',
],
];
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$settings = $this
->getSettings();
$element['markup'] = [
'#type' => 'text_format',
'#title' => $this
->t('Markup'),
'#default_value' => isset($settings['markup']['value']) ? $settings['markup']['value'] : '',
'#format' => !empty($settings['markup']['format']) ? $settings['markup']['format'] : filter_default_format(),
'#required' => TRUE,
'#rows' => 15,
'#description' => $this
->t('The markup to be displayed. Any HTML is legal here, so be careful not to break your page layout.'),
];
$element['instructions'] = [
'#markup' => htmlentities($this
->t('This is a special field. It will output the markup below, on the node/edit form for this content type. Consider wrapping any visible output in <div class="form-item"></div> to follow form standards.')),
'#weight' => -1,
];
return $element;
}
}
Classes
Name |
Description |
MarkupItem |
Plugin implementation of the 'markup' field type. |