ScheduledPublish.php in Scheduled Publish 8
File
src/Plugin/Field/FieldType/ScheduledPublish.php
View source
<?php
namespace Drupal\scheduled_publish\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
class ScheduledPublish extends DateTimeItem {
public static function defaultStorageSettings() {
return [];
}
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
return [];
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['moderation_state'] = DataDefinition::create('string')
->setLabel(t('The moderation state.'));
return $properties;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['moderation_state'] = [
'type' => 'varchar',
'length' => 32,
];
return $schema;
}
public function isEmpty() {
return empty($this
->get('moderation_state')
->getValue()) || empty($this
->get('value')
->getValue());
}
}