Newer
Older
<?php
/**
* @file
Alex Pott
committed
* Contains \Drupal\text\Plugin\Field\FieldType\TextWithSummaryItem.
*/
Alex Pott
committed
namespace Drupal\text\Plugin\Field\FieldType;
Alex Pott
committed
use Drupal\Core\Field\FieldStorageDefinitionInterface;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
/**
* Plugin implementation of the 'text_with_summary' field type.
*
* @FieldType(
* id = "text_with_summary",
* label = @Translation("Text (formatted, long, with summary)"),
* description = @Translation("This field stores long text with a format and an optional summary."),
* category = @Translation("Text"),
* default_widget = "text_textarea_with_summary",
* default_formatter = "text_default"
* )
*/
class TextWithSummaryItem extends TextItemBase {
/**
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
return array(
'display_summary' => 0,
) + parent::defaultFieldSettings();
}
/**
* {@inheritdoc}
*/
Alex Pott
committed
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;
}
/**
* {@inheritdoc}
*/
Alex Pott
committed
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',
'length' => 255,
),
),
'indexes' => array(
'format' => array('format'),
),
);
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('summary')->getValue();
return parent::isEmpty() && ($value === NULL || $value === '');
}
/**
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array();
$settings = $this->getSettings();
$element['display_summary'] = array(
'#type' => 'checkbox',
'#title' => t('Summary input'),
Alex Pott
committed
'#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;
}
}