Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Issue-693: Disallow scheduler on locked pages (if scheduler module is enabled) " #768

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"drupal/real_aes": "^2.5",
"drupal/redirect": "^1.6",
"drupal/redis": "^1.7",
"drupal/scheduler": "^2.1",
"drupal/search_api": "^1.18",
"drupal/search_api_pantheon": "^8.2",
"drupal/search_api_solr": "^4.3.2",
Expand Down
76 changes: 1 addition & 75 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 1 addition & 50 deletions web/modules/custom/server_general/server_general.module
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ function server_general_form_alter(array &$form, FormStateInterface $form_state)
if (!$form_object instanceof ContentEntityFormInterface) {
return;
}

/** @var \Drupal\node\NodeInterface $entity */
$entity = $form_object->getEntity();
// Check that entity is a node.
Expand All @@ -227,41 +228,6 @@ function server_general_form_alter(array &$form, FormStateInterface $form_state)
/** @var \Drupal\server_general\LockedPages $locked_pages_service */
$locked_pages_service = \Drupal::service('server_general.locked_pages');

// Do nothing if scheduler module is not installed and node is not locked.
if (!\Drupal::moduleHandler()->moduleExists('scheduler') && !$locked_pages_service->isNodeLocked($entity)) {
return;
}

$publish_on = $entity->get('publish_on')->value;
$unpublish_on = $entity->get('unpublish_on')->value;
// If node is locked and schedule dates are not set,
// remove publish_on, unpublish_on and scheduler_settings.
if (!$publish_on && !$unpublish_on && $locked_pages_service->isNodeLocked($entity)) {
$scheduler_fields = ['publish_on', 'unpublish_on', 'scheduler_settings'];
foreach (array_keys($form) as $key) {
if (in_array($key, $scheduler_fields)) {
unset($form[$key]);
}
}
}

$request_time = \Drupal::time()->getCurrentTime();
// If node is locked and schedule dates are set,
// make them readonly and disabled.
if (($publish_on > $request_time) && ($unpublish_on > $request_time) && $locked_pages_service->isNodeLocked($entity)) {
$form['scheduler_settings']['#description'] = [
'#type' => 'inline_template',
'#template' => '<strong class="action-link--danger">{{ message }}</strong>',
'#context' => [
'message' => t("This page is locked hence the publish and unpublish dates can not be changed. Also scheduling dates won't work."),
],
];
$form['publish_on']['widget'][0]['value']['#attributes']['readonly'] = 'readonly';
$form['publish_on']['widget'][0]['value']['#attributes']['disabled'] = TRUE;
$form['unpublish_on']['widget'][0]['value']['#attributes']['readonly'] = 'readonly';
$form['unpublish_on']['widget'][0]['value']['#attributes']['disabled'] = TRUE;
}

// Check if node is locked or not.
if (!$locked_pages_service->isNodeLocked($entity)) {
return;
Expand Down Expand Up @@ -387,18 +353,3 @@ function server_general_preprocess_media_oembed_iframe(array &$variables) {
$variables['media'] = IFrameMarkup::create(str_replace('youtube.com/', 'youtube-nocookie.com/', $variables['media']));
}
}

/**
* Implements hook_scheduler_unpublishing_allowed().
*/
function server_general_scheduler_unpublishing_allowed(EntityInterface $entity) {
// Do nothing if node is not a landing page.
if ($entity->bundle() !== 'landing_page') {
return;
}

/** @var \Drupal\server_general\LockedPages $locked_pages_service */
$locked_pages_service = \Drupal::service('server_general.locked_pages');

return !$locked_pages_service->isNodeLocked($entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Drupal\Tests\server_general\ExistingSite;

use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\node\Entity\NodeType;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -175,73 +173,4 @@ public function testLockedHomepage() {
$this->assertSession()->statusCodeEquals(Response::HTTP_FORBIDDEN);
}

/**
* Test schedular for locked page.
*/
public function testSchedularOnLockedPage() {
// Install the scheduler module.
$module_installer = \Drupal::service('module_installer');
assert($module_installer instanceof ModuleInstallerInterface);
$module_installer->install(['scheduler']);

// Enable scheduler for Landing Page content type.
$node_type = NodeType::load('landing_page');
$node_type
->setThirdPartySetting('scheduler', 'publish_enable', TRUE)
->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE)
->save();
$node_type->save();

// Enable the scheduler fields in the default form display, mimicking
// what would be done if the entity bundle had been enabled via admin UI.
$this->container->get('entity_display.repository')
->getFormDisplay('node', 'landing_page')
->setComponent('publish_on', ['type' => 'datetime_timestamp_no_default'])
->setComponent('unpublish_on', ['type' => 'datetime_timestamp_no_default'])
->save();

// Login as admin.
$user = $this->createUser();
$user->addRole('administrator');
$user->save();
$this->drupalLogin($user);

// Create not locked page for admin.
$node = $this->createNode([
'title' => 'Testing not locked page',
'uid' => $user->id(),
'type' => 'landing_page',
'moderation_state' => 'published',
]);

$node->setPublished()->save();

$this->drupalGet($node->toUrl('edit-form'));
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);

// Check schedular options exists.
$this->assertSession()->pageTextContains('Scheduling options');
$this->assertSession()->elementExists('css', '.scheduler-form');

// Make page locked.
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = \Drupal::entityTypeManager();
/** @var \Drupal\config_pages\ConfigPagesStorage $config_pages_storage */
$config_pages_storage = $entity_type_manager->getStorage('config_pages');
/** @var \Drupal\Core\Entity\ContentEntityInterface|null $main_settings */
$main_settings = $config_pages_storage->load('main_settings');

$main_settings->get('field_locked_pages')->appendItem(['target_id' => $node->id()]);
$main_settings->save();

$this->drupalGet($node->toUrl('edit-form'));
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
// Check schedular options not exists.
$this->assertSession()->pageTextNotContains('Scheduling options');
$this->assertSession()->elementNotExists('css', '.scheduler-form');

$main_settings->get('field_locked_pages')->removeItem(1);
$main_settings->save();
}

}