Skip to content

Commit 213ab22

Browse files
authored
[SITE-5342] Add proper publish and unpublish support. (#32)
1 parent 30d4e2a commit 213ab22

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

src/Entity/PantheonDocument.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Drupal\Core\Entity\ContentEntityBase;
88
use Drupal\Core\Entity\EntityChangedTrait;
9+
use Drupal\Core\Entity\EntityPublishedInterface;
10+
use Drupal\Core\Entity\EntityPublishedTrait;
911
use Drupal\Core\Entity\EntityTypeInterface;
1012
use Drupal\Core\Field\BaseFieldDefinition;
1113
use Drupal\Core\StringTranslation\TranslatableMarkup;
@@ -47,6 +49,7 @@
4749
* "bundle" = "collection",
4850
* "label" = "title",
4951
* "uuid" = "uuid",
52+
* "published" = "status",
5053
* },
5154
* links = {
5255
* "collection" = "/admin/content/pantheon-content-publisher",
@@ -59,13 +62,15 @@
5962
class PantheonDocument extends ContentEntityBase implements PantheonDocumentInterface {
6063

6164
use EntityChangedTrait;
65+
use EntityPublishedTrait;
6266

6367
/**
6468
* {@inheritdoc}
6569
*/
6670
public static function baseFieldDefinitions(EntityTypeInterface $entity_type): array {
6771

6872
$fields = parent::baseFieldDefinitions($entity_type);
73+
$fields += static::publishedBaseFieldDefinitions($entity_type);
6974
// In order to work around the InnoDB 191 character limit on utf8mb4
7075
// primary keys, we set the character set for the field to ASCII.
7176
$fields['id'] = BaseFieldDefinition::create('string')
@@ -110,10 +115,9 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
110115
])
111116
->setDisplayConfigurable('view', TRUE);
112117

113-
$fields['status'] = BaseFieldDefinition::create('boolean')
114-
->setLabel(t('Status'))
115-
->setDefaultValue(TRUE)
116-
->setSetting('on_label', 'Enabled')
118+
$fields['status']
119+
->setDescription(t('A boolean value indicating whether the document is published. Controlled externally by Content Publisher.'))
120+
->setDisplayConfigurable('form', FALSE)
117121
->setDisplayOptions('view', [
118122
'region' => 'hidden',
119123
])

src/GraphQL.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function getArticle(string $id): array {
3333
'slug',
3434
'createdAt',
3535
'publishedDate',
36+
'publishStatus',
3637
'metadata',
3738
]);
3839
return $this->request($query);

src/PantheonContentPublisherConverter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function convert(array $pantheon_data, string $collection_name, string|in
6060
$date_convert = fn (&$x) => $x ? $this->date($x) : (int) $_SERVER['REQUEST_TIME'];
6161
return $drupal_data + [
6262
'id' => $id,
63+
'status' => ($pantheon_data['publishStatus'] ?? '') === 'published',
6364
'collection' => $collection_name,
6465
'content' => $pantheon_data['content'] ?? '',
6566
'title' => $pantheon_data['title'] ?? '',

src/PantheonDocumentInterface.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66

77
use Drupal\Core\Entity\ContentEntityInterface;
88
use Drupal\Core\Entity\EntityChangedInterface;
9+
use Drupal\Core\Entity\EntityPublishedInterface;
910

1011
/**
1112
* Provides an interface defining a pantheon content publisher entity type.
1213
*/
13-
interface PantheonDocumentInterface extends ContentEntityInterface, EntityChangedInterface {
14+
interface PantheonDocumentInterface extends ContentEntityInterface, EntityChangedInterface, EntityPublishedInterface {
15+
16+
/**
17+
* Denotes that the document is not published.
18+
*/
19+
const NOT_PUBLISHED = 0;
20+
21+
/**
22+
* Denotes that the document is published.
23+
*/
24+
const PUBLISHED = 1;
1425

1526
}

src/PantheonDocumentListBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function buildRow(EntityInterface $entity): array {
3131
/** @var \Drupal\pantheon_content_publisher\PantheonDocumentInterface $entity */
3232
$row['id'] = $entity->id();
3333
$row['label'] = $entity->toLink();
34-
$row['status'] = $entity->get('status')->value ? $this->t('Enabled') : $this->t('Disabled');
34+
$row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Draft');
3535
$row['created']['data'] = $entity->get('created')->view(['label' => 'hidden']);
3636
$row['changed']['data'] = $entity->get('changed')->view(['label' => 'hidden']);
3737
return $row;

0 commit comments

Comments
 (0)