TextWithSummaryItem.php in Zircon Profile 8.0
File
core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php
View source
<?php
namespace Drupal\text\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
class TextWithSummaryItem extends TextItemBase {
public static function defaultFieldSettings() {
return array(
'display_summary' => 0,
) + parent::defaultFieldSettings();
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['summary'] = DataDefinition::create('string')
->setLabel(t('Summary'));
$properties['summary_processed'] = DataDefinition::create('string')
->setLabel(t('Processed summary'))
->setDescription(t('The summary text with the text format applied.'))
->setComputed(TRUE)
->setClass('\\Drupal\\text\\TextProcessed')
->setSetting('text source', 'summary');
return $properties;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
'type' => 'text',
'size' => 'big',
),
'summary' => array(
'type' => 'text',
'size' => 'big',
),
'format' => array(
'type' => 'varchar_ascii',
'length' => 255,
),
),
'indexes' => array(
'format' => array(
'format',
),
),
);
}
public function isEmpty() {
$value = $this
->get('summary')
->getValue();
return parent::isEmpty() && ($value === NULL || $value === '');
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array();
$settings = $this
->getSettings();
$element['display_summary'] = array(
'#type' => 'checkbox',
'#title' => t('Summary input'),
'#default_value' => $settings['display_summary'],
'#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'),
);
return $element;
}
}