diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StatusItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StatusItem.php new file mode 100644 index 0000000..ddae58d --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StatusItem.php @@ -0,0 +1,39 @@ +getValue() == -1) { + return TRUE; + } + else { + return FALSE; + } + } + +} diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index b4fd6aa..b3124d0 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\field\Entity\FieldStorageConfig; @@ -179,3 +180,18 @@ function comment_update_8200() { /** * @} End of "addtogroup updates-8.2.x". */ + +/** + * Switch status from boolean to integer. + */ +function comment_update_8300() { + $manager = \Drupal::entityDefinitionUpdateManager(); + $definition = BaseFieldDefinition::create('status') + ->setName('status') + ->setTargetEntityTypeId('comment') + ->setLabel(t('Publishing status')) + ->setDescription(t('An integer indicating the comment status.')) + ->setTranslatable(TRUE) + ->setDefaultValue(1); + $manager->updateFieldStorageDefinition($definition); +} \ No newline at end of file diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index d626be3..fe1d641 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -285,11 +285,11 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The time that the comment was last edited.')) ->setTranslatable(TRUE); - $fields['status'] = BaseFieldDefinition::create('boolean') + $fields['status'] = BaseFieldDefinition::create('status') ->setLabel(t('Publishing status')) - ->setDescription(t('A boolean indicating whether the comment is published.')) + ->setDescription(t('An integer indicating the comment status.')) ->setTranslatable(TRUE) - ->setDefaultValue(TRUE); + ->setDefaultValue(1); $fields['thread'] = BaseFieldDefinition::create('string') ->setLabel(t('Thread place')) diff --git a/core/modules/node/node.install b/core/modules/node/node.install index c754880..191039c 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -218,3 +218,19 @@ function node_update_8003() { $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition($field_name, 'node')); } } + +/** + * Switch status from boolean to integer. + */ +function node_update_8004() { + $manager = \Drupal::entityDefinitionUpdateManager(); + $definition = BaseFieldDefinition::create('status') + ->setName('status') + ->setTargetEntityTypeId('node') + ->setLabel(t('Publishing status')) + ->setDescription(t('A integer indicating the node status.')) + ->setRevisionable(TRUE) + ->setTranslatable(TRUE) + ->setDefaultValue(1); + $manager->updateFieldStorageDefinition($definition); +} diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index bdb8050..e4555d4 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -408,12 +408,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )) ->setDisplayConfigurable('form', TRUE); - $fields['status'] = BaseFieldDefinition::create('boolean') + $fields['status'] = BaseFieldDefinition::create('status') ->setLabel(t('Publishing status')) - ->setDescription(t('A boolean indicating whether the node is published.')) + ->setDescription(t('A integer indicating the node status.')) ->setRevisionable(TRUE) ->setTranslatable(TRUE) - ->setDefaultValue(TRUE); + ->setDefaultValue(1); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Authored on')) diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index 61def5a..f2e849d 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -449,6 +449,13 @@ protected function mapSingleFieldViewsData($table, $field_name, $field_type, $co $views_field['sort']['id'] = 'standard'; break; + case 'status': + $views_field['field']['id'] = 'field'; + $views_field['argument']['id'] = 'numeric'; + $views_field['filter']['id'] = 'status'; + $views_field['sort']['id'] = 'standard'; + break; + case 'uri': // Let's render URIs as URIs by default, not links. $views_field['field']['id'] = 'field'; diff --git a/core/modules/views/src/Plugin/views/filter/Status.php b/core/modules/views/src/Plugin/views/filter/Status.php new file mode 100644 index 0000000..9109680 --- /dev/null +++ b/core/modules/views/src/Plugin/views/filter/Status.php @@ -0,0 +1,32 @@ +valueOptions)) { + $this->valueOptions = [ + -1 => $this->t('Archived'), + 0 => $this->t('Unpublished'), + 1 => $this->t('Published'), + 2 => $this->t('Forward revision'), + ]; + } + + return $this->valueOptions; + } + +} diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc index 93a659c..6223b45 100644 --- a/core/modules/views/views.views.inc +++ b/core/modules/views/views.views.inc @@ -514,6 +514,9 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora if ($field_storage->getType() == 'boolean') { $filter = 'boolean'; } + elseif ($field_storage->getType() == 'status') { + $filter = 'status'; + } break; case 'text': case 'blob':