Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
Hide the publishing status checkbox on existing and new moderation-en…
Browse files Browse the repository at this point in the history
…abled content types (#480)
  • Loading branch information
Adam authored and balsama committed Oct 6, 2017
1 parent 74e4729 commit 43b84c6
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ install:
# Execute database updates, if there are any.
- drupal update:execute
# Execute manual updates.
- drupal update:lightning --no-interaction
- drupal update:lightning --no-interaction --since=$VERSION

before_script:
- drush runserver --default-server=builtin 8080 &>/dev/null &
Expand Down
5 changes: 5 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ are currently running Beta 1 and are trying to update to Beta 3, you will need
to follow the instructions for updating from Beta 1 to Beta 2, then from Beta 2
to Beta 3, in that order.

### 2.2.0 to 2.2.1
* Visit *Structure > Content types*. For each moderated content type, click
"Manage form display", then drag the "Publishing status" field into the
"Disabled" section and press "Save".

### 2.1.8 to 2.2.0
There are no manual update steps for this version.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ content:
placeholder: ''
third_party_settings: { }
region: content
status:
type: boolean_checkbox
settings:
display_label: true
weight: 120
region: content
third_party_settings: { }
scheduled_update:
type: inline_entity_form_complex
weight: 8
Expand All @@ -83,4 +76,5 @@ content:
match_operator: CONTAINS
third_party_settings: { }
region: content
hidden: { }
hidden:
status: true
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ content:
placeholder: ''
third_party_settings: { }
region: content
status:
type: boolean_checkbox
settings:
display_label: true
weight: 120
region: content
third_party_settings: { }
hidden:
promote: true
status: true
sticky: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ use Drupal\views\ViewEntityInterface;
use Drupal\views\ViewExecutable;
use Drupal\workbench_moderation\Entity\ModerationState;

/**
* Implements hook_form_FORM_ID_alter().
*/
function lightning_workflow_form_node_type_moderation_form_alter(array &$form, FormStateInterface $form_state) {
$form['actions']['submit']['#submit'][] = 'lightning_workflow_submit_node_type_moderation_form';
}

function lightning_workflow_submit_node_type_moderation_form(array &$form, FormStateInterface $form_state) {
$was_moderated = (bool) $form['enable_moderation_state']['#default_value'];
$now_moderated = (bool) $form_state->getValue('enable_moderation_state');

if (!$was_moderated && $now_moderated) {
/** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
$form_object = $form_state->getFormObject();

entity_get_form_display('node', $form_object->getEntity()->id(), 'default')
->removeComponent('status')
->save();
}
}

/**
* Implements hook_theme_registry_alter().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Drupal\lightning_workflow\Update;

use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\node\NodeTypeInterface;
use Drupal\workbench_moderation\ModerationInformationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Executes interactive update steps for Lightning Workflow 2.2.1.
*
* @Update("2.2.1")
*/
final class Update221 implements ContainerInjectionInterface {

use StringTranslationTrait;

/**
* The node type entity storage handler.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $nodeTypeStorage;

/**
* The node entity type definition.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $nodeDefinition;

/**
* The moderation information service.
*
* @var \Drupal\workbench_moderation\ModerationInformationInterface
*/
protected $moderationInfo;

public function __construct(EntityStorageInterface $node_type_storage, EntityTypeInterface $node_definition, ModerationInformationInterface $moderation_info, TranslationInterface $translation) {
$this->nodeTypeStorage = $node_type_storage;
$this->nodeDefinition = $node_definition;
$this->moderationInfo = $moderation_info;
$this->setStringTranslation($translation);
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager')->getStorage('node_type'),
$container->get('entity_type.manager')->getDefinition('node'),
$container->get('workbench_moderation.moderation_information'),
$container->get('string_translation')
);
}

/**
* Returns all moderated node types.
*
* @return NodeTypeInterface[]
*/
protected function getNodeTypes() {
$filter = function (NodeTypeInterface $node_type) {
return $this->moderationInfo->isModeratableBundle($this->nodeDefinition, $node_type->id());
};
return array_filter($this->nodeTypeStorage->loadMultiple(), $filter);
}

/**
* @update
*/
public function hideStatusCheckboxes(DrupalStyle $io) {
/** @var NodeTypeInterface $node_type */
foreach ($this->getNodeTypes() as $node_type) {
$question = (string) $this->t('Do you want to ensure the "Publishing status" checkbox is hidden on the @node_type content type form?', [
'@node_type' => $node_type->label(),
]);

if ($io->confirm($question)) {
entity_get_form_display('node', $node_type->id(), 'default')
->removeComponent('status')
->save();
}
}
}

}
11 changes: 6 additions & 5 deletions src/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function getProviderVersion($provider) {

return isset($versions[$provider])
? $versions[$provider]
: '0.0.0';
: '2.2.0';
}

protected function getDefinitions() {
Expand Down Expand Up @@ -158,13 +158,14 @@ protected function runTasks($handler, DrupalStyle $io) {
/** @var DocBlock $doc_block */
list ($reflector, $doc_block) = $task;

$proceed = TRUE;
if ($doc_block->hasTag('ask')) {
$tags = $doc_block->getTagsByName('ask');

$proceed = $io->confirm(reset($tags)->getContent());
if ($proceed) {
$reflector->invoke($handler, $io);
}
}

if ($proceed) {
$reflector->invoke($handler, $io);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ content:
field_meta_tags:
type: metatag_firehose
region: content
weight: 121
weight: 26
settings: { }
third_party_settings: { }
panelizer:
Expand All @@ -51,13 +51,6 @@ content:
settings: { }
third_party_settings: { }
region: content
status:
type: boolean_checkbox
settings:
display_label: true
weight: 120
region: content
third_party_settings: { }
title:
type: string_textfield
weight: 0
Expand All @@ -77,4 +70,5 @@ content:
region: content
hidden:
promote: true
status: true
sticky: true
14 changes: 4 additions & 10 deletions tests/config/core.entity_form_display.node.page.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ content:
field_meta_tags:
type: metatag_firehose
region: content
weight: 122
weight: 27
settings: { }
third_party_settings: { }
path:
Expand All @@ -62,16 +62,9 @@ content:
allow_existing: false
match_operator: CONTAINS
form_mode: default
weight: 121
weight: 26
third_party_settings: { }
region: content
status:
type: boolean_checkbox
settings:
display_label: true
weight: 120
region: content
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
Expand All @@ -96,4 +89,5 @@ content:
placeholder: ''
third_party_settings: { }
region: content
hidden: { }
hidden:
status: true
32 changes: 32 additions & 0 deletions tests/features/workflow/moderation_states.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ Feature: Workflow moderation states
When I visit "admin/content"
Then I should see "Lazy Lummox"

@084ca18d
Scenario: Content types do not display the Published checkbox once they are moderated
Given node_type entities:
| type | name |
| foobar | Foobar |
And I am logged in as a user with the administrator role
When I visit "/admin/structure/types/manage/foobar/moderation"
And I check the box "Enable moderation states."
And I press "Save"
And I visit "/node/add/foobar"
Then I should see the "Save" button
But I should not see a "status[value]" field
And I should not see the "Save and publish" button
And I should not see the "Save as unpublished" button

@d0f9aaa8
Scenario: Unmoderated content types have normal submit buttons
Given node_type entities:
Expand All @@ -102,9 +117,26 @@ Feature: Workflow moderation states
And I am logged in as a user with the "administer nodes,create not_moderated content" permissions
When I visit "/node/add/not_moderated"
Then I should see the "Save" button
And the "Published" checkbox should be checked
And I should not see the "Save and publish" button
And I should not see the "Save as unpublished" button

@14ddcc9d
Scenario Outline: Moderated content types do not show the Published checkbox
Given I am logged in as a user with the <role> role
When I visit "/node/add/<node_type>"
Then I should see the "Save" button
But I should not see a "status[value]" field
And I should not see the "Save and publish" button
And I should not see the "Save as unpublished" button

Examples:
| node_type | role |
| page | page_creator |
| page | administrator |
| landing_page | landing_page_creator |
| landing_page | administrator |

@7cef449b
Scenario: Unmoderated content types have the "Create new revision" Checkbox
Given node_type entities:
Expand Down

0 comments on commit 43b84c6

Please sign in to comment.