Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/scheduler
  • issue/scheduler-1345666
  • issue/scheduler-3167193
  • issue/scheduler-3175184
  • issue/scheduler-2416135
  • issue/scheduler-2096585
  • issue/scheduler-3206654
  • issue/scheduler-2941946
  • issue/scheduler-3180264
  • issue/scheduler-3221220
  • issue/scheduler-3221289
  • issue/scheduler-3196989
  • issue/scheduler-3225635
  • issue/scheduler-3225695
  • issue/scheduler-3227338
  • issue/scheduler-3224340
  • issue/scheduler-3232857
  • issue/scheduler-3238728
  • issue/scheduler-2977887
  • issue/scheduler-3282068
  • issue/scheduler-3282982
  • issue/scheduler-3282071
  • issue/scheduler-3282341
  • issue/scheduler-3244884
  • issue/scheduler-3248470
  • issue/scheduler-3238953
  • issue/scheduler-3155034
  • issue/scheduler-3251399
  • issue/scheduler-3252531
  • issue/scheduler-3249050
  • issue/scheduler-3260070
  • issue/scheduler-3260215
  • issue/scheduler-3260067
  • issue/scheduler-3259200
  • issue/scheduler-3265440
  • issue/scheduler-2916730
  • issue/scheduler-3268149
  • issue/scheduler-3268167
  • issue/scheduler-3266795
  • issue/scheduler-3037483
  • issue/scheduler-3268584
  • issue/scheduler-3267429
  • issue/scheduler-3270082
  • issue/scheduler-3272548
  • issue/scheduler-3273938
  • issue/scheduler-3284289
  • issue/scheduler-3276637
  • issue/scheduler-3285242
  • issue/scheduler-3291771
  • issue/scheduler-3176822
  • issue/scheduler-3317185
  • issue/scheduler-3293936
  • issue/scheduler-3311425
  • issue/scheduler-3297995
  • issue/scheduler-3289475
  • issue/scheduler-3271462
  • issue/scheduler-3312069
  • issue/scheduler-3312200
  • issue/scheduler-3049585
  • issue/scheduler-3318332
  • issue/scheduler-3313443
  • issue/scheduler-3313848
  • issue/scheduler-3314158
  • issue/scheduler-3314267
  • issue/scheduler-3314451
  • issue/scheduler-3317944
  • issue/scheduler-3210321
  • issue/scheduler-3316719
  • issue/scheduler-3318972
  • issue/scheduler-3326114
  • issue/scheduler-3320341
  • issue/scheduler-3331246
  • issue/scheduler-3336108
  • issue/scheduler-3080979
  • issue/scheduler-3336969
  • issue/scheduler-3356800
  • issue/scheduler-3357619
  • issue/scheduler-3357836
  • issue/scheduler-3358806
  • issue/scheduler-3358927
  • issue/scheduler-3359081
  • issue/scheduler-3359093
  • issue/scheduler-3359532
  • issue/scheduler-3359790
  • issue/scheduler-3400631
  • issue/scheduler-3401828
  • issue/scheduler-3285427
  • issue/scheduler-3371935
  • issue/scheduler-3373725
  • issue/scheduler-3373860
  • issue/scheduler-3376411
  • issue/scheduler-3369158
  • issue/scheduler-3360744
  • issue/scheduler-3387331
  • issue/scheduler-3388029
  • issue/scheduler-3388199
  • issue/scheduler-3389642
  • issue/scheduler-3390389
  • issue/scheduler-3386861
  • issue/scheduler-3393356
  • issue/scheduler-3397181
  • issue/scheduler-3412854
  • issue/scheduler-3417444
  • issue/scheduler-2907382
  • issue/scheduler-3418728
  • issue/scheduler-3420859
  • issue/scheduler-3421936
  • issue/scheduler-3421984
  • issue/scheduler-3417340
  • issue/scheduler-3221881
  • issue/scheduler-3427971
  • issue/scheduler-3446881
  • issue/scheduler-3442356
  • issue/scheduler-3437739
  • issue/scheduler-3439850
  • issue/scheduler-3445052
  • issue/scheduler-3443183
  • issue/scheduler-3359998
  • issue/scheduler-3434325
  • issue/scheduler-3432376
  • issue/scheduler-3432976
  • issue/scheduler-3442310
  • issue/scheduler-3440026
  • issue/scheduler-3451111
  • issue/scheduler-3451287
  • issue/scheduler-3451737
  • issue/scheduler-3451750
  • issue/scheduler-3103334
  • issue/scheduler-3453345
  • issue/scheduler-3453360
  • issue/scheduler-3453359
  • issue/scheduler-3454508
  • issue/scheduler-3456628
  • issue/scheduler-3458430
  • issue/scheduler-3463141
  • issue/scheduler-3463136
  • issue/scheduler-3463494
  • issue/scheduler-3465015
  • issue/scheduler-3465213
  • issue/scheduler-3458578
  • issue/scheduler-3423469
  • issue/scheduler-3423200
  • issue/scheduler-3467349
  • issue/scheduler-3468320
  • issue/scheduler-3469273
  • issue/scheduler-3282128
  • issue/scheduler-3473851
  • issue/scheduler-3249560
  • issue/scheduler-3476450
  • issue/scheduler-3454624
  • issue/scheduler-3477201
  • issue/scheduler-3477348
  • issue/scheduler-3476369
  • issue/scheduler-3480311
  • issue/scheduler-3480501
  • issue/scheduler-3327577
  • issue/scheduler-3481016
  • issue/scheduler-3493930
  • issue/scheduler-3495229
  • issue/scheduler-2712465
  • issue/scheduler-3496138
  • issue/scheduler-3500296
  • issue/scheduler-3498553
  • issue/scheduler-3500821
  • issue/scheduler-3502530
  • issue/scheduler-3507012
  • issue/scheduler-3363972
  • issue/scheduler-3510926
  • issue/scheduler-3512795
  • issue/scheduler-3513815
  • issue/scheduler-2984054
171 results
Show changes
Commits on Source (11)
Showing
with 426 additions and 88 deletions
...@@ -24,21 +24,19 @@ jobs: ...@@ -24,21 +24,19 @@ jobs:
- NODE=YES - NODE=YES
- PRODUCT=YES - PRODUCT=YES
- RULES=YES - RULES=YES
# ---- Remaining self deprecation notices (2911) # ---- Remaining self deprecation notices (0)
# 2911 ModuleHandlerInterface::getImplementations() is deprecated in drupal:9.4.0
# ---- Other deprecation notices (0) # ---- Other deprecation notices (0)
- DEPRECATIONS=2911 - DEPRECATIONS=0
- php: 8.1 - php: 8.1
env: env:
- DRUPAL_CORE=9.5.x - DRUPAL_CORE=9.5.x
- MEDIA=YES - MEDIA=YES
- TAXONOMY=YES - TAXONOMY=YES
# ---- Unsilenced deprecation notices (6) # ---- Unsilenced deprecation notices (6)
# 6 strlen(): Passing null to parameter #1 ($string) is deprecated # 6 strlen(): Passing null to parameter #1 ($string) is deprecated (SchedulerDrushTest)
# ---- Remaining self deprecation notices (1767) # ---- Remaining self deprecation notices (0)
# 1767 ModuleHandlerInterface::getImplementations() is deprecated in drupal:9.4.0
# ---- Other deprecation notices (0) # ---- Other deprecation notices (0)
- DEPRECATIONS=1773 - DEPRECATIONS=6
- php: 8.1 - php: 8.1
env: env:
# Run the Node tests only. # Run the Node tests only.
......
services: services:
php: php:
image: q0rban/tugboat-drupal:9.3 image: q0rban/tugboat-drupal:10.0
default: true default: true
http: false http: false
depends: mysql depends: mysql
...@@ -8,6 +8,9 @@ services: ...@@ -8,6 +8,9 @@ services:
init: | init: |
# Install the bcmath extension, required for commerce_product # Install the bcmath extension, required for commerce_product
docker-php-ext-install bcmath docker-php-ext-install bcmath
# JPEG support is not included by default, but it is needed when generating content.
docker-php-ext-configure gd --enable-gd --with-jpeg
docker-php-ext-install gd
update: | update: |
set -eux set -eux
...@@ -32,6 +35,21 @@ services: ...@@ -32,6 +35,21 @@ services:
# above that uses the $TUGBOAT_REPO_ID environment variable. # above that uses the $TUGBOAT_REPO_ID environment variable.
composer require drupal/scheduler:dev-$TUGBOAT_REPO_ID composer require drupal/scheduler:dev-$TUGBOAT_REPO_ID
# Install Drupal on the site.
vendor/bin/drush \
--yes \
--db-url=mysql://tugboat:tugboat@mysql:3306/tugboat \
--site-name="${TUGBOAT_PREVIEW_NAME}" \
--account-pass=admin \
site:install standard
# Show site status and GD image support status.
vendor/bin/drush status-report
vendor/bin/drush php:eval 'phpinfo()' | grep GD
vendor/bin/drush php:eval 'print "imagepng() " . (function_exists("imagepng") ? "--yes\n" : "--no\n"); '
vendor/bin/drush php:eval 'print "imagejpeg() " . (function_exists("imagejpeg") ? "--yes\n" : "--no\n"); '
vendor/bin/drush php:eval 'print_r(gd_info());'
# Commerce 2.29 needs inline_entity_form which does not have a stable # Commerce 2.29 needs inline_entity_form which does not have a stable
# version as at March 2022. Therefore get that package here allowing RC # version as at March 2022. Therefore get that package here allowing RC
# to avoid the "does not match your minimum-stability" problem. # to avoid the "does not match your minimum-stability" problem.
...@@ -40,17 +58,13 @@ services: ...@@ -40,17 +58,13 @@ services:
# Get other useful modules. # Get other useful modules.
composer require drupal/devel_generate composer require drupal/devel_generate
composer require drupal/module_filter
composer require drupal/workbench_moderation
composer require drupal/workbench_moderation_actions:dev-1.x
# Install Drupal on the site. # These modules are not compatible with Drupal 10 (yet) so only get them
vendor/bin/drush \ # when running Drupal 9.
--yes \ vendor/bin/drush core:status | awk "NR==1{print \$2\$3\$4}"
--db-url=mysql://tugboat:tugboat@mysql:3306/tugboat \ vendor/bin/drush core:status | awk "NR==1{print \$2\$3\$4}" | \
--site-name="Scheduler issue ${TUGBOAT_PREVIEW_NAME}" \ grep version:9 && composer require drupal/module_filter drupal/workbench_moderation \
--account-pass=admin \ drupal/workbench_moderation_actions:1.x-dev drupal/admin_toolbar
site:install standard
# Set up the files directory permissions. # Set up the files directory permissions.
mkdir -p $DRUPAL_DOCROOT/sites/default/files mkdir -p $DRUPAL_DOCROOT/sites/default/files
...@@ -59,8 +73,11 @@ services: ...@@ -59,8 +73,11 @@ services:
chmod -R g+w $DRUPAL_DOCROOT/sites/default/files chmod -R g+w $DRUPAL_DOCROOT/sites/default/files
# Enable modules. # Enable modules.
vendor/bin/drush --yes pm:enable scheduler devel devel_generate \ vendor/bin/drush --yes pm:enable scheduler devel devel_generate media commerce_product
module_filter media commerce_product
# Enable modules that are only available at Drupal 9.
vendor/bin/drush core:status | awk "NR==1{print \$2\$3\$4}" | \
grep version:9 && vendor/bin/drush --yes pm:enable module_filter admin_toolbar
# Show versions. # Show versions.
composer show drupal/scheduler | egrep 'name |vers' composer show drupal/scheduler | egrep 'name |vers'
...@@ -143,14 +160,17 @@ services: ...@@ -143,14 +160,17 @@ services:
vendor/bin/drush user-add-role 'product_viewer' 'Proctor product viewer' vendor/bin/drush user-add-role 'product_viewer' 'Proctor product viewer'
# Generate content. # Generate content.
vendor/bin/drush devel-generate-content 2 --bundles=article --authors=1,2 --verbose vendor/bin/drush devel-generate-content 3 --bundles=article --authors=1,2 --verbose
vendor/bin/drush devel-generate-content 2 --bundles=page --authors=1,2 --verbose vendor/bin/drush devel-generate-content 3 --bundles=page --authors=1,2 --verbose
vendor/bin/drush devel-generate-media 4 --media-types=image --verbose vendor/bin/drush devel-generate-media 3 --media-types=document --verbose
vendor/bin/drush devel-generate-media 3 --media-types=image --verbose
# @todo Place the 'Switch users' block in first sidebar. # @todo Place the 'Switch users' block in first sidebar.
# @todo Add 'content overview' and 'media overview' to tools menu. # @todo Add 'content overview' and 'media overview' to tools menu.
# @todo Create a store for products. Then create some products. # @todo Create a store for products. Then create some products.
# @todo Generate a vocabulary and some terms. Create users for taxonomy. # @todo Generate a vocabulary and some terms. Create users for taxonomy.
# @todo page entity type should not be promoted to front page.
# @todo Create a menu of links to the pages?
build: | build: |
set -eux set -eux
......
...@@ -2,3 +2,11 @@ ...@@ -2,3 +2,11 @@
.scheduler-admin-form > .dropbutton-wrapper { .scheduler-admin-form > .dropbutton-wrapper {
width: 30%; width: 30%;
} }
/* Add default background to dropbutton items in Claro theme. This should only
affect the non-link group title items, and avoid them being transparent.
See https://www.drupal.org/project/scheduler/issues/3316719
and https://www.drupal.org/project/drupal/issues/3317323 */
.scheduler-admin-form .dropbutton__item:first-of-type ~ .dropbutton__item {
background-color: #f2f4f5;
}
...@@ -9,6 +9,7 @@ build: ...@@ -9,6 +9,7 @@ build:
host_command: host_command:
commands: commands:
# Apply patch from https://www.drupal.org/project/drupalci_testbot/issues/3251817 # Apply patch from https://www.drupal.org/project/drupalci_testbot/issues/3251817
# @todo Remove this when Drupal 9.4.9 and 9.5.0 and 10.0.0 have been released.
- "cd ${SOURCE_DIR} && sudo -u www-data curl https://www.drupal.org/files/issues/2021-11-30/3251817-4.run-tests-with-multiple-groups.patch | sudo -u www-data patch -p1 --verbose" - "cd ${SOURCE_DIR} && sudo -u www-data curl https://www.drupal.org/files/issues/2021-11-30/3251817-4.run-tests-with-multiple-groups.patch | sudo -u www-data patch -p1 --verbose"
csslint: csslint:
eslint: eslint:
...@@ -21,9 +22,9 @@ build: ...@@ -21,9 +22,9 @@ build:
# Rule 3.0-alpha7 is not compatible with PHP8.1 but the dev version has been fixed. # Rule 3.0-alpha7 is not compatible with PHP8.1 but the dev version has been fixed.
- "cd ${SOURCE_DIR} && sudo -u www-data composer require drupal/rules:3.x-dev" - "cd ${SOURCE_DIR} && sudo -u www-data composer require drupal/rules:3.x-dev"
# Get workbench moderation modules when testing with Drupal 9. # Get workbench moderation modules when testing with Drupal 9.
# WBMA 1.0 cannot be installed with D9, so use * to allow the dev version. # Use * because only the dev version of WBMA is compatible with D9.
- 'drush status | awk "NR==1{print \$2\$3\$4}"' - 'drush core:status | awk "NR==1{print \$2\$3\$4}"'
- 'drush status | awk "NR==1{print \$2\$3\$4}" | grep version:9 && sudo -u www-data composer require drupal/workbench_moderation:* drupal/workbench_moderation_actions:*' - 'drush core:status | awk "NR==1{print \$2\$3\$4}" | grep version:9 && sudo -u www-data composer require drupal/workbench_moderation drupal/workbench_moderation_actions:*'
# Show the eslint version # Show the eslint version
- "${SOURCE_DIR}/core/node_modules/.bin/eslint --version" - "${SOURCE_DIR}/core/node_modules/.bin/eslint --version"
run_tests.functional: run_tests.functional:
......
...@@ -78,6 +78,18 @@ function scheduler_install() { ...@@ -78,6 +78,18 @@ function scheduler_install() {
->save(); ->save();
} }
/**
* Implements hook_uninstall().
*/
function scheduler_uninstall() {
// This should not be necessary but incase the entity db tables or config have
// got out-of-step with the Scheduler plugins make sure all is up to date so
// that uninstalling will run OK.
$scheduler_manager = \Drupal::service('scheduler.manager');
$scheduler_manager->entityUpdate();
$scheduler_manager->entityRevert();
}
/** /**
* Reset date and time formats to default. * Reset date and time formats to default.
*/ */
...@@ -228,13 +240,25 @@ function scheduler_update_8205() { ...@@ -228,13 +240,25 @@ function scheduler_update_8205() {
/** /**
* Remove Scheduler fields and third_party_settings for Paragraph entity types. * Remove Scheduler fields and third_party_settings for Paragraph entity types.
*/ */
function scheduler_update_8206() { function scheduler_update_8207() {
$scheduler_manager = \Drupal::service('scheduler.manager'); // update_8206 had a typo, therefore replaced with update_8207.
// Check the module is enabled, to avoid 'Unknown entity type' message. // Check the module is enabled, to avoid 'Unknown entity type' message.
if (\Drupal::moduleHandler()->moduleExists('paragraph') && ($result = $scheduler_manager->entityRevert(['paragraph']))) { if (\Drupal::moduleHandler()->moduleExists('paragraphs') && ($result = \Drupal::service('scheduler.manager')->entityRevert(['paragraph']))) {
return t('%updated.', ['%updated' => implode(', ', $result)]); return t('%updated.', ['%updated' => implode(', ', $result)]);
} }
else { else {
return t('No Paragraph entity types require reverting.'); return t('No update required.');
}
}
/**
* Show/hide entity form fields to match Scheduling enabled/disabled settings.
*/
function scheduler_update_8208() {
if ($result = \Drupal::service('scheduler.manager')->resetFormDisplayFields()) {
return implode('</li><li>', $result);
}
else {
return t('No update required.');
} }
} }
...@@ -534,6 +534,9 @@ function _scheduler_entity_type_form_alter(&$form, FormStateInterface $form_stat ...@@ -534,6 +534,9 @@ function _scheduler_entity_type_form_alter(&$form, FormStateInterface $form_stat
]; ];
$form['#entity_builders'][] = '_scheduler_form_entity_type_form_builder'; $form['#entity_builders'][] = '_scheduler_form_entity_type_form_builder';
// Add a custom submit handler to adjust the fields in the form displays.
$form['actions']['submit']['#submit'][] = '_scheduler_form_entity_type_submit';
} }
/** /**
...@@ -554,6 +557,64 @@ function _scheduler_form_entity_type_form_builder($entity_type, $type, &$form, F ...@@ -554,6 +557,64 @@ function _scheduler_form_entity_type_form_builder($entity_type, $type, &$form, F
$type->setThirdPartySetting('scheduler', 'unpublish_revision', $form_state->getValue('scheduler_unpublish_revision')); $type->setThirdPartySetting('scheduler', 'unpublish_revision', $form_state->getValue('scheduler_unpublish_revision'));
} }
/**
* Entity type form submit handler.
*/
function _scheduler_form_entity_type_submit($form, FormStateInterface $form_state) {
// Get the entity type id (node, media, taxonomy_term, etc.)
$entity_type_id = $form_state->getFormObject()->getEntity()->getEntityType()->getBundleOf();
// Get the entity bundle id (page, article, image, etc.)
$bundle_id = $form_state->getFormObject()->getEntity()->id();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
// Get all active display modes. getFormModes() returns the additional modes
// then add the default.
$all_display_modes = array_keys($display_repository->getFormModes($entity_type_id));
$all_display_modes[] = $display_repository::DEFAULT_DISPLAY_MODE;
$supported_display_modes = \Drupal::service('scheduler.manager')->getPlugin($entity_type_id)->entityFormDisplayModes();
// Each of the active form display modes may need to be adjusted to add or
// remove the scheduler fields depending on the 'enable' setting.
foreach ($all_display_modes as $display_mode) {
$form_display = $display_repository->getFormDisplay($entity_type_id, $bundle_id, $display_mode);
// If this bundle is not enabled for scheduled publishing or the form
// display mode is not supported then make sure the publish_on field is
// disabled in the form display.
if (!$form_state->getValue('scheduler_publish_enable') || !in_array($display_mode, $supported_display_modes)) {
$form_display->removeComponent('publish_on')->save();
}
// @todo Find a more robust way to detect that the checkbox was off before.
elseif (!$form['scheduler']['publish']['scheduler_publish_enable']['#default_value']) {
// If the entity bundle is now enabled for scheduled publishing but was
// not enabled before then set the publish_on field to be displayed and
// set the widget type to 'datetime_timestamp_no_default'. Only do this
// when the checkbox has been changed, because the widget could be altered
// or the field moved by a subsequent process or manually by admin.
$form_display->setComponent('scheduler_settings', ['weight' => 50])
->setComponent('publish_on', ['type' => 'datetime_timestamp_no_default', 'weight' => 52])->save();
}
// Do the same for the unpublish_on field.
if (!$form_state->getValue('scheduler_unpublish_enable') || !in_array($display_mode, $supported_display_modes)) {
$form_display->removeComponent('unpublish_on')->save();
}
elseif (!$form['scheduler']['unpublish']['scheduler_unpublish_enable']['#default_value']) {
$form_display->setComponent('scheduler_settings', ['weight' => 50])
->setComponent('unpublish_on', ['type' => 'datetime_timestamp_no_default', 'weight' => 54])->save();
}
// If the display mode is not supported then also remove the
// scheduler_settings group fieldset.
if (!in_array($display_mode, $supported_display_modes)) {
$form_display->removeComponent('scheduler_settings')->save();
}
}
}
/** /**
* Form alter handling for Devel Generate forms. * Form alter handling for Devel Generate forms.
*/ */
...@@ -699,7 +760,7 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) { ...@@ -699,7 +760,7 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) {
->setLabel(t('Publish on')) ->setLabel(t('Publish on'))
->setDisplayOptions('form', [ ->setDisplayOptions('form', [
'type' => 'datetime_timestamp_no_default', 'type' => 'datetime_timestamp_no_default',
'weight' => 30, 'region' => 'hidden',
]) ])
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setTranslatable(TRUE) ->setTranslatable(TRUE)
...@@ -710,7 +771,7 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) { ...@@ -710,7 +771,7 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) {
->setLabel(t('Unpublish on')) ->setLabel(t('Unpublish on'))
->setDisplayOptions('form', [ ->setDisplayOptions('form', [
'type' => 'datetime_timestamp_no_default', 'type' => 'datetime_timestamp_no_default',
'weight' => 30, 'region' => 'hidden',
]) ])
->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('form', TRUE)
->setTranslatable(TRUE) ->setTranslatable(TRUE)
...@@ -1016,11 +1077,11 @@ function scheduler_entity_extra_field_info() { ...@@ -1016,11 +1077,11 @@ function scheduler_entity_extra_field_info() {
$unpublishing_enabled = $type->getThirdPartySetting('scheduler', 'unpublish_enable', $config->get('default_unpublish_enable')); $unpublishing_enabled = $type->getThirdPartySetting('scheduler', 'unpublish_enable', $config->get('default_unpublish_enable'));
if ($publishing_enabled || $unpublishing_enabled) { if ($publishing_enabled || $unpublishing_enabled) {
// Weight 20 puts this below the core fields by default. // Weight 50 puts this below the core fields by default.
$fields[$entityTypeId][$type->id()]['form']['scheduler_settings'] = [ $fields[$entityTypeId][$type->id()]['form']['scheduler_settings'] = [
'label' => t('Scheduler Dates'), 'label' => t('Scheduler Dates'),
'description' => t('Fieldset containing Scheduler Publish-on and Unpublish-on date input fields'), 'description' => t('Fieldset containing Scheduler Publish-on and Unpublish-on date input fields'),
'weight' => 20, 'weight' => 50,
]; ];
} }
} }
...@@ -1175,6 +1236,11 @@ function scheduler_cache_flush() { ...@@ -1175,6 +1236,11 @@ function scheduler_cache_flush() {
* Implements hook_migrate_prepare_row(). * Implements hook_migrate_prepare_row().
*/ */
function scheduler_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { function scheduler_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
// getMigrationTags can return null for a custom migration, so skip these.
if (is_null($migration->getMigrationTags())) {
return;
}
// Process node type third-party-settings. // Process node type third-party-settings.
if (in_array('Scheduler Settings', $migration->getMigrationTags())) { if (in_array('Scheduler Settings', $migration->getMigrationTags())) {
$scheduler_config_name = [ $scheduler_config_name = [
......
...@@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityInterface; ...@@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url; use Drupal\Core\Url;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
...@@ -252,7 +253,7 @@ class SchedulerManager { ...@@ -252,7 +253,7 @@ class SchedulerManager {
$query->accessCheck(FALSE); $query->accessCheck(FALSE);
// If the entity type is revisionable then make sure we look for the // If the entity type is revisionable then make sure we look for the
// latest revision. This is important for moderated entities. // latest revision. This is important for moderated entities.
if ($this->entityTypeManager->getDefinition($entityTypeId)->isRevisionable()) { if ($plugin->entityTypeObject()->isRevisionable()) {
$query->latestRevision(); $query->latestRevision();
} }
$ids = $query->execute(); $ids = $query->execute();
...@@ -473,7 +474,7 @@ class SchedulerManager { ...@@ -473,7 +474,7 @@ class SchedulerManager {
$query->accessCheck(FALSE); $query->accessCheck(FALSE);
// If the entity type is revisionable then make sure we look for the // If the entity type is revisionable then make sure we look for the
// latest revision. This is important for moderated entities. // latest revision. This is important for moderated entities.
if ($this->entityTypeManager->getDefinition($entityTypeId)->isRevisionable()) { if ($plugin->entityTypeObject()->isRevisionable()) {
$query->latestRevision(); $query->latestRevision();
} }
$ids = $query->execute(); $ids = $query->execute();
...@@ -903,7 +904,7 @@ class SchedulerManager { ...@@ -903,7 +904,7 @@ class SchedulerManager {
// Avoid errors when an implementation of hook_scheduler_{type}_list has // Avoid errors when an implementation of hook_scheduler_{type}_list has
// added an id of the wrong type. // added an id of the wrong type.
if (!$entity = $storage->load($id)) { if (!$entity = $storage->load($id)) {
$this->logger->notice('Entity id @id is not a @type entity. Processing skipped.', [ $this->logger->warning('Entity id @id is not a @type entity. Processing skipped.', [
'@id' => $id, '@id' => $id,
'@type' => $type, '@type' => $type,
]); ]);
...@@ -1001,15 +1002,15 @@ class SchedulerManager { ...@@ -1001,15 +1002,15 @@ class SchedulerManager {
/** /**
* Get a plugin for a specific entity type. * Get a plugin for a specific entity type.
* *
* @param string $entity_type * @param string $entityTypeId
* The entity type. * The entity type id, for example 'node' or 'media'.
* *
* @return mixed * @return mixed
* The plugin object associated with a specific entity, or NULL if none. * The plugin object associated with a specific entity, or NULL if none.
*/ */
public function getPlugin($entity_type) { public function getPlugin($entityTypeId) {
$plugins = $this->getPlugins(); $plugins = $this->getPlugins();
return $plugins[$entity_type] ?? NULL; return $plugins[$entityTypeId] ?? NULL;
} }
/** /**
...@@ -1232,13 +1233,13 @@ class SchedulerManager { ...@@ -1232,13 +1233,13 @@ class SchedulerManager {
$view->set('_core', $core); $view->set('_core', $core);
$view->set('uuid', $uuid); $view->set('uuid', $uuid);
$view->save(); $view->save();
$this->logger->notice('%view view updated.', ['%view' => $source['label']]); $this->logger->info('%view view updated.', ['%view' => $source['label']]);
} }
else { else {
// The view does not exist in active storage so import it from source. // The view does not exist in active storage so import it from source.
$view = $view_storage->createFromStorageRecord($source); $view = $view_storage->createFromStorageRecord($source);
$view->save(); $view->save();
$this->logger->notice('%view view loaded from source.', ['%view' => $source['label']]); $this->logger->info('%view view loaded from source.', ['%view' => $source['label']]);
} }
$updated[] = $source['label']; $updated[] = $source['label'];
} }
...@@ -1302,10 +1303,10 @@ class SchedulerManager { ...@@ -1302,10 +1303,10 @@ class SchedulerManager {
// If the field is marked as deleted then remove it. // If the field is marked as deleted then remove it.
if ($change == $entityUpdateManager::DEFINITION_DELETED && $field = $entityUpdateManager->getFieldStorageDefinition($field_name, $entity_type_id)) { if ($change == $entityUpdateManager::DEFINITION_DELETED && $field = $entityUpdateManager->getFieldStorageDefinition($field_name, $entity_type_id)) {
$entityUpdateManager->uninstallFieldStorageDefinition($field); $entityUpdateManager->uninstallFieldStorageDefinition($field);
$output["$entity_type_id fields"] = $this->t('Scheduler fields removed from @entityType', [ $output["{$entity_type_id} fields"] = $this->t('Scheduler fields removed from @entityType', [
'@entityType' => $entityType->getLabel(), '@entityType' => $entityType->getLabel(),
]); ]);
$this->logger->notice('%field field removed from %entityType entity type', [ $this->logger->info('%field field removed from %entityType entity type', [
'%field' => $field->getLabel(), '%field' => $field->getLabel(),
'%entityType' => $entityType->getLabel(), '%entityType' => $entityType->getLabel(),
]); ]);
...@@ -1322,11 +1323,11 @@ class SchedulerManager { ...@@ -1322,11 +1323,11 @@ class SchedulerManager {
foreach (array_keys($third_party_settings) as $setting) { foreach (array_keys($third_party_settings) as $setting) {
$bundle->unsetThirdPartySetting('scheduler', $setting)->save(); $bundle->unsetThirdPartySetting('scheduler', $setting)->save();
} }
$this->logger->notice('Scheduler settings removed from %entity %bundle', [ $this->logger->info('Scheduler settings removed from %entity %bundle', [
'%entity' => $bundle->getEntityType()->getLabel(), '%entity' => $bundle->getEntityType()->getLabel(),
'%bundle' => $bundle->label(), '%bundle' => $bundle->label(),
]); ]);
$output["{$bundle->id()} settings"] = $this->t('@bundle settings removed', [ $output["{$bundle->id()} settings"] = $this->t('Settings removed from @bundle', [
'@bundle' => $bundle->label(), '@bundle' => $bundle->label(),
]); ]);
} }
...@@ -1336,4 +1337,127 @@ class SchedulerManager { ...@@ -1336,4 +1337,127 @@ class SchedulerManager {
return $output; return $output;
} }
/**
* Reset the form display fields to match the Scheduler enabled settings.
*
* The Scheduler fields are disabled by default and only enabled in a form
* display when that entity bundle is enabled for scheduled publishing or
* unpublishing. See _scheduler_form_entity_type_submit() for details.
*
* This was a design change during the development of Scheduler 2.0 and any
* site that had installed Scheduler prior to 2.0-rc8 will have all fields
* enabled. Whilst this should not be a problem, it is preferrable to update
* the displays to match the scenario when the modules is freshly installed.
* Hence this function was added and called from scheduler_update_8208().
*/
public function resetFormDisplayFields() {
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
$fields_displayed = [];
$fields_hidden = [];
foreach ($this->getPlugins() as $entityTypeId => $plugin) {
// Get all active display modes. getFormModes() returns the additional
// modes then add the default.
$all_display_modes = array_keys($display_repository->getFormModes($entityTypeId));
$all_display_modes[] = $display_repository::DEFAULT_DISPLAY_MODE;
$supported_display_modes = $plugin->entityFormDisplayModes();
$bundles = $plugin->getTypes();
foreach ($bundles as $bundle_id => $bundle) {
foreach ($all_display_modes as $display_mode) {
$form_display = $display_repository->getFormDisplay($entityTypeId, $bundle_id, $display_mode);
foreach (['publish', 'unpublish'] as $value) {
$field = $value . '_on';
$setting = $value . '_enable';
// If this bundle is not enabled for scheduled (un)publishing or the
// form display mode is not supported then remove the field.
if (!$bundle->getThirdPartySetting('scheduler', $setting, FALSE) || !in_array($display_mode, $supported_display_modes)) {
$form_display->removeComponent($field)->save();
if ($display_mode == $display_repository::DEFAULT_DISPLAY_MODE) {
$fields_hidden[$field]["{$bundle->getEntityType()->getCollectionLabel()}"][] = $bundle->label();
}
}
else {
// Scheduling is enabled. Get the existing component to preserve
// any changed settings, but if the type is empty or set the to
// the core default 'datetime_timestamp' then change it to
// Scheduler's 'datetime_timestamp_no_default'.
$component = $form_display->getComponent($field);
if (empty($component['type']) || $component['type'] == 'datetime_timestamp') {
$component['type'] = 'datetime_timestamp_no_default';
}
$component['weight'] = ($field == 'publish_on' ? 52 : 54);
// Make sure the field and the settings group are displayed.
$form_display->setComponent('scheduler_settings', ['weight' => 50])
->setComponent($field, $component)->save();
if ($display_mode == $display_repository::DEFAULT_DISPLAY_MODE) {
$fields_displayed[$field]["{$bundle->getEntityType()->getCollectionLabel()}"][] = $bundle->label();
}
}
}
// If the display mode is not supported remove the group fieldset.
if (!in_array($display_mode, $supported_display_modes)) {
$form_display->removeComponent('scheduler_settings')->save();
}
}
}
}
// It is not possible to determine whether a field on an enabled entity type
// had been manually hidden before this update. It is a rare scenario but
// inform the admin that there is potentially some manual work to do.
$uri = 'https://www.drupal.org/project/scheduler/issues/3320341';
$link = Link::fromTextAndUrl($this->t('Scheduler issue 3320341'), Url::fromUri($uri));
\Drupal::messenger()->addMessage($this->t(
'The Scheduler fields are now hidden by default and automatically changed to be displayed when an entity
bundle is enabled for scheduling. If you have previously manually hidden scheduler fields for enabled
entity types then these fields will now be displayed. You will need to manually hide them again or
implement hook_scheduler_hide_publish_date() or hook_scheduler_{TYPE}_hide_publish_date() and the
equivalent for unpublish_date. See @issue for details.',
['@issue' => $link->toString()]), MessengerInterface::TYPE_STATUS, FALSE);
$this->logger->warning(
'The Scheduler fields are now hidden by default and automatically changed to be displayed when an entity
bundle is enabled for scheduling. If you have previously manually hidden scheduler fields for enabled
entity types then these fields will now be displayed. You will need to manually hide them again or
implement hook_scheduler_hide_publish_date() or hook_scheduler_{TYPE}_hide_publish_date() and the
equivalent for unpublish_date. See @issue for details.',
['@issue' => $link->toString(), 'link' => $link->toString()]
);
/**
* Helper function to format the list of fields on bundles.
*/
function formatOutputText($fields) {
return implode(', ', array_map(function ($name, $bundles) {
return "$name (" . implode(',', $bundles) . ")";
}, array_keys($fields), $fields));
}
$output = [];
if (isset($fields_displayed['publish_on'])) {
$output[] = $this->t('Publish On field displayed for: @list', [
'@list' => formatOutputText($fields_displayed['publish_on']),
]);
}
if (isset($fields_displayed['unpublish_on'])) {
$output[] = $this->t('Unpublish On field displayed for: @list', [
'@list' => formatOutputText($fields_displayed['unpublish_on']),
]);
}
if (isset($fields_hidden['publish_on'])) {
$output[] = $this->t('Publish On field hidden for: @list', [
'@list' => formatOutputText($fields_hidden['publish_on']),
]);
}
if (isset($fields_hidden['unpublish_on'])) {
$output[] = $this->t('Unpublish On field hidden for: @list', [
'@list' => formatOutputText($fields_hidden['unpublish_on']),
]);
}
return $output;
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\scheduler; namespace Drupal\scheduler;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -17,6 +18,13 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -17,6 +18,13 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
*/ */
protected $entityTypeManager; protected $entityTypeManager;
/**
* The entity type object for this plugin.
*
* @var Drupal\Core\Config\Entity\ConfigEntityType
*/
protected $entityTypeObject;
/** /**
* A static cache of create/edit entity form IDs. * A static cache of create/edit entity form IDs.
* *
...@@ -37,6 +45,8 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -37,6 +45,8 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition); $instance = new static($configuration, $plugin_id, $plugin_definition);
$instance->entityTypeManager = $container->get('entity_type.manager'); $instance->entityTypeManager = $container->get('entity_type.manager');
$instance->entityTypeObject = $instance->entityTypeManager
->getDefinition($plugin_definition['entityType']);
return $instance; return $instance;
} }
...@@ -70,6 +80,16 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -70,6 +80,16 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
return $this->pluginDefinition['entityType']; return $this->pluginDefinition['entityType'];
} }
/**
* Get the entity type object supported by this plugin.
*
* @return Drupal\Core\Config\Entity\ConfigEntityType
* The entity type object.
*/
public function entityTypeObject() {
return $this->entityTypeObject;
}
/** /**
* Get module dependency. * Get module dependency.
* *
...@@ -159,9 +179,7 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -159,9 +179,7 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
* The name of the type/bundle field for this entity type. * The name of the type/bundle field for this entity type.
*/ */
public function typeFieldName() { public function typeFieldName() {
return $this->entityTypeManager return $this->entityTypeObject->getKey('bundle');
->getDefinition($this->entityType())
->getKey('bundle');
} }
/** /**
...@@ -171,12 +189,10 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -171,12 +189,10 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
* The type/bundle objects, keyed by type/bundle name. * The type/bundle objects, keyed by type/bundle name.
*/ */
public function getTypes() { public function getTypes() {
$bundleDefinition = $this->entityTypeManager $bundleEntityType = $this->entityTypeObject->getBundleEntityType();
->getDefinition($this->entityType())
->getBundleEntityType();
return $this->entityTypeManager return $this->entityTypeManager
->getStorage($bundleDefinition) ->getStorage($bundleEntityType)
->loadMultiple(); ->loadMultiple();
} }
...@@ -199,9 +215,7 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -199,9 +215,7 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
return $this->entityTypeFormIds; return $this->entityTypeFormIds;
} }
$bundleEntityType = $this->entityTypeManager $bundleEntityType = $this->entityTypeObject->getBundleEntityType();
->getDefinition($this->entityType())
->getBundleEntityType();
return $this->entityTypeFormIds = $this->entityFormIdsByType($bundleEntityType, TRUE); return $this->entityTypeFormIds = $this->entityFormIdsByType($bundleEntityType, TRUE);
} }
...@@ -258,4 +272,11 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin ...@@ -258,4 +272,11 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
return array_unique($ids); return array_unique($ids);
} }
/**
* Return all supported entity form display modes.
*/
public function entityFormDisplayModes() {
return [EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE];
}
} }
...@@ -128,4 +128,21 @@ interface SchedulerPluginInterface { ...@@ -128,4 +128,21 @@ interface SchedulerPluginInterface {
*/ */
public function entityTypeFormIds(); public function entityTypeFormIds();
/**
* Return all supported entity edit form display modes.
*
* \Drupal\Core\Entity\EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE
* is the 'default' display mode and this is always supported. If there are no
* other supported modes then this function does not need to be implemented in
* the plugin. However if additional form display modes are provided by other
* modules and Scheduler has been updated to support these modes for editting
* the entity, then the plugin implementaion of this function should return
* all supported modes including 'default'. The implementation does not need
* to check if the third-party module is actually available or enabled.
*
* @return array
* A list of entity form display mode ids.
*/
public function entityFormDisplayModes();
} }
...@@ -6,10 +6,6 @@ namespace Drupal\Tests\scheduler\Functional; ...@@ -6,10 +6,6 @@ namespace Drupal\Tests\scheduler\Functional;
* Tests the Scheduler interaction with Devel Generate module. * Tests the Scheduler interaction with Devel Generate module.
* *
* @group scheduler * @group scheduler
* @group legacy
* @todo Remove the 'legacy' tag when Devel no longer uses the deprecated
* $published parameter for setPublished(), and does not use functions
* drupal_set_message(), format_date() and db_query_range().
*/ */
class SchedulerDevelGenerateTest extends SchedulerBrowserTestBase { class SchedulerDevelGenerateTest extends SchedulerBrowserTestBase {
......
...@@ -7,6 +7,10 @@ use Drupal\Core\Url; ...@@ -7,6 +7,10 @@ use Drupal\Core\Url;
/** /**
* Tests the display of date entry fields and form elements. * Tests the display of date entry fields and form elements.
* *
* @todo Extend these tests to cover form display processing when entity
* type is enabled/disabled.
* @see https://www.drupal.org/project/scheduler/issues/3320341
*
* @group scheduler * @group scheduler
*/ */
class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase { class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase {
...@@ -27,17 +31,7 @@ class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase { ...@@ -27,17 +31,7 @@ class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase {
*/ */
public function testEntityTypeForm($entityTypeId, $bundle, $operation) { public function testEntityTypeForm($entityTypeId, $bundle, $operation) {
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
$entityType = $this->entityTypeObject($entityTypeId, $bundle);
$bundle_id = $entityType->bundle();
if ($operation == 'edit') {
$url = Url::fromRoute("entity.{$bundle_id}.edit_form", [$bundle_id => $bundle]);
}
else {
// The route for adding a 'node' entity type has a different format
// compared to the new standard for all other entity types.
$url = Url::fromRoute($entityTypeId == 'node' ? 'node.type_add' : "entity.{$bundle_id}.add_form");
}
if ($operation == 'add first') { if ($operation == 'add first') {
// Delete all the entity types for this bundle, to check that 'add' // Delete all the entity types for this bundle, to check that 'add'
// works when it would be the first type being added. // works when it would be the first type being added.
...@@ -45,6 +39,7 @@ class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase { ...@@ -45,6 +39,7 @@ class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase {
$this->entityTypeObject($entityTypeId, 'non-enabled')->delete(); $this->entityTypeObject($entityTypeId, 'non-enabled')->delete();
} }
$url = $this->adminUrl($operation == 'edit' ? 'bundle_edit' : 'bundle_add', $entityTypeId, $bundle);
$this->drupalGet($url); $this->drupalGet($url);
$this->assertSession()->fieldExists('edit-scheduler-publish-enable'); $this->assertSession()->fieldExists('edit-scheduler-publish-enable');
$this->assertSession()->fieldExists('edit-scheduler-unpublish-enable'); $this->assertSession()->fieldExists('edit-scheduler-unpublish-enable');
...@@ -60,8 +55,8 @@ class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase { ...@@ -60,8 +55,8 @@ class SchedulerFieldsDisplayTest extends SchedulerBrowserTestBase {
$types = $this->dataStandardEntityTypes(); $types = $this->dataStandardEntityTypes();
$data = []; $data = [];
foreach ($types as $key => $values) { foreach ($types as $key => $values) {
$data["$key-1"] = array_merge($values, ['add']); $data["$key-1"] = array_merge($values, ['add first']);
$data["$key-2"] = array_merge($values, ['add first']); $data["$key-2"] = array_merge($values, ['add']);
$data["$key-3"] = array_merge($values, ['edit']); $data["$key-3"] = array_merge($values, ['edit']);
} }
return $data; return $data;
......
...@@ -9,12 +9,22 @@ namespace Drupal\Tests\scheduler\Functional; ...@@ -9,12 +9,22 @@ namespace Drupal\Tests\scheduler\Functional;
*/ */
class SchedulerNonEnabledTypeTest extends SchedulerBrowserTestBase { class SchedulerNonEnabledTypeTest extends SchedulerBrowserTestBase {
/**
* Additional core module field_ui is required for entity form display page.
*
* @var array
*/
protected static $modules = ['field_ui'];
/** /**
* Tests the publish_enable and unpublish_enable entity type settings. * Tests the publish_enable and unpublish_enable entity type settings.
* *
* @dataProvider dataNonEnabledScenarios() * @dataProvider dataNonEnabledScenarios()
*/ */
public function testNonEnabledType($id, $entityTypeId, $bundle, $description, $publishing_enabled, $unpublishing_enabled) { public function testNonEnabledType($id, $entityTypeId, $bundle, $description, $publishing_enabled, $unpublishing_enabled) {
// Give adminUser the permissions to use the field_ui 'manage form display'
// tab for the entity type being tested.
$this->addPermissionsToUser($this->adminUser, ["administer {$entityTypeId} form display"]);
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
$entityType = $this->entityTypeObject($entityTypeId, $bundle); $entityType = $this->entityTypeObject($entityTypeId, $bundle);
$storage = $this->entityStorageObject($entityTypeId); $storage = $this->entityStorageObject($entityTypeId);
...@@ -23,6 +33,22 @@ class SchedulerNonEnabledTypeTest extends SchedulerBrowserTestBase { ...@@ -23,6 +33,22 @@ class SchedulerNonEnabledTypeTest extends SchedulerBrowserTestBase {
// The 'default' case specifically checks the behavior of the unchanged // The 'default' case specifically checks the behavior of the unchanged
// settings, so only change these when not running the default test. // settings, so only change these when not running the default test.
if ($description != 'Default') { if ($description != 'Default') {
// Set the enabled checkboxes via entity type admin form. This will also
// partially test the form display adjustments.
$this->drupalGet($this->adminUrl('bundle_edit', $entityTypeId, $bundle));
$edit = [
'scheduler_publish_enable' => $publishing_enabled,
'scheduler_unpublish_enable' => $unpublishing_enabled,
];
$this->submitForm($edit, 'Save');
// Show the form display page for info.
$this->drupalGet($this->adminUrl('bundle_form_display', $entityTypeId, $bundle));
// ThirdPartySettings are set correctly by saving the entity type form,
// however this does not get replicated back to $entityType here (is this
// a bug is core test traits somewhere?). Thwerefore resort to setting the
// values here too.
$entityType->setThirdPartySetting('scheduler', 'publish_enable', $publishing_enabled) $entityType->setThirdPartySetting('scheduler', 'publish_enable', $publishing_enabled)
->setThirdPartySetting('scheduler', 'unpublish_enable', $unpublishing_enabled) ->setThirdPartySetting('scheduler', 'unpublish_enable', $unpublishing_enabled)
->save(); ->save();
......
...@@ -94,6 +94,14 @@ trait SchedulerCommerceProductSetupTrait { ...@@ -94,6 +94,14 @@ trait SchedulerCommerceProductSetupTrait {
->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE) ->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE)
->save(); ->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('commerce_product', $this->productTypeName)
->setComponent('publish_on', ['type' => 'datetime_timestamp_no_default'])
->setComponent('unpublish_on', ['type' => 'datetime_timestamp_no_default'])
->save();
// Add the body field using the existing commerce_product function. // Add the body field using the existing commerce_product function.
commerce_product_add_body_field($this->productType); commerce_product_add_body_field($this->productType);
......
...@@ -79,6 +79,14 @@ trait SchedulerMediaSetupTrait { ...@@ -79,6 +79,14 @@ trait SchedulerMediaSetupTrait {
->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE) ->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE)
->save(); ->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('media', $this->mediaTypeName)
->setComponent('publish_on', ['type' => 'datetime_timestamp_no_default'])
->setComponent('unpublish_on', ['type' => 'datetime_timestamp_no_default'])
->save();
// Create a test media type for audio which is not enabled for scheduling. // Create a test media type for audio which is not enabled for scheduling.
/** @var \Drupal\media\Entity\MediaTypeInterface $nonSchedulerMediaType */ /** @var \Drupal\media\Entity\MediaTypeInterface $nonSchedulerMediaType */
$this->nonSchedulerMediaType = $this->createMediaType('audio_file', [ $this->nonSchedulerMediaType = $this->createMediaType('audio_file', [
......
...@@ -131,6 +131,14 @@ trait SchedulerSetupTrait { ...@@ -131,6 +131,14 @@ trait SchedulerSetupTrait {
->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE) ->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE)
->save(); ->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', $this->type)
->setComponent('publish_on', ['type' => 'datetime_timestamp_no_default'])
->setComponent('unpublish_on', ['type' => 'datetime_timestamp_no_default'])
->save();
// The majority of tests use the standard Scheduler-enabled content type but // The majority of tests use the standard Scheduler-enabled content type but
// we also need a content type which is not enabled for Scheduler. // we also need a content type which is not enabled for Scheduler.
$this->nonSchedulerNodeType = $this->drupalCreateContentType([ $this->nonSchedulerNodeType = $this->drupalCreateContentType([
...@@ -479,10 +487,10 @@ trait SchedulerSetupTrait { ...@@ -479,10 +487,10 @@ trait SchedulerSetupTrait {
} }
/** /**
* Returns the url for a specified page and entity type. * Returns the url for a specified page, entity type and optionally bundle.
* *
* @param string $page * @param string $page
* The page required - 'collection', 'scheduled' or 'generate'. * The page required - 'collection', 'scheduled', 'generate', etc.
* @param string $entityTypeId * @param string $entityTypeId
* The machine id of the entity type - 'node', 'media', 'commerce_product'. * The machine id of the entity type - 'node', 'media', 'commerce_product'.
* @param string $bundle * @param string $bundle
...@@ -492,28 +500,38 @@ trait SchedulerSetupTrait { ...@@ -492,28 +500,38 @@ trait SchedulerSetupTrait {
* The url for the required page. * The url for the required page.
*/ */
public function adminUrl($page, $entityTypeId, $bundle = NULL) { public function adminUrl($page, $entityTypeId, $bundle = NULL) {
// @todo Could be changed to use a route and parameter like entityAddUrl(). // $bundle_id will be 'node_type', 'media_type', 'commerce_product_type',
// 'taxonomy_vocabulary' etc.
$bundle_id = $this->container->get('entity_type.manager')->getDefinition($entityTypeId)->getBundleEntityType();
$urls = [ $urls = [
'collection' => [ 'collection' => [
'node' => 'admin/content', 'node' => Url::fromRoute('system.admin_content'),
'media' => 'admin/content/media', 'taxonomy_term' => Url::fromRoute('entity.taxonomy_vocabulary.overview_form', [$bundle_id => $bundle]),
'commerce_product' => 'admin/commerce/products', 'default' => Url::fromRoute("entity.{$entityTypeId}.collection"),
'taxonomy_term' => "admin/structure/taxonomy/manage/$bundle/overview",
], ],
'scheduled' => [ 'scheduled' => [
'node' => 'admin/content/scheduled', 'node' => Url::fromRoute('view.scheduler_scheduled_content.overview'),
'media' => 'admin/content/media/scheduled', 'default' => Url::fromRoute("view.scheduler_scheduled_{$entityTypeId}.overview"),
'commerce_product' => 'admin/commerce/products/scheduled',
'taxonomy_term' => 'admin/structure/taxonomy/scheduled',
], ],
'generate' => [ 'generate' => [
'node' => 'admin/config/development/generate/content', 'node' => Url::fromRoute('devel_generate.content'),
'media' => 'admin/config/development/generate/media', 'media' => Url::fromRoute('devel_generate.media'),
'taxonomy_term' => 'admin/config/development/generate/term', 'taxonomy_term' => Url::fromRoute('devel_generate.term'),
],
'bundle_add' => [
'node' => Url::fromRoute('node.type_add'),
'default' => Url::fromRoute("entity.{$bundle_id}.add_form"),
],
'bundle_edit' => [
'default' => Url::fromRoute("entity.{$bundle_id}.edit_form", [$bundle_id => $bundle]),
],
'bundle_form_display' => [
'default' => Url::fromRoute("entity.entity_form_display.{$entityTypeId}.default", [$bundle_id => $bundle]),
], ],
]; ];
$url = $urls[$page][$entityTypeId] ?? NULL; $url = $urls[$page][$entityTypeId] ?? ($urls[$page]['default'] ?? NULL);
if (empty($url)) { if (empty($url)) {
// Incorrect parameter values. // Incorrect parameter values.
throw new \Exception(sprintf('Unrecognised combination of page "%s", entityTypeId "%s" and bundle "%s" passed to adminUrl()', $page, $entityTypeId, $bundle)); throw new \Exception(sprintf('Unrecognised combination of page "%s", entityTypeId "%s" and bundle "%s" passed to adminUrl()', $page, $entityTypeId, $bundle));
......
...@@ -79,6 +79,14 @@ trait SchedulerTaxonomyTermSetupTrait { ...@@ -79,6 +79,14 @@ trait SchedulerTaxonomyTermSetupTrait {
->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE) ->setThirdPartySetting('scheduler', 'unpublish_enable', TRUE)
->save(); ->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('taxonomy_term', $this->vocabularyId)
->setComponent('publish_on', ['type' => 'datetime_timestamp_no_default'])
->setComponent('unpublish_on', ['type' => 'datetime_timestamp_no_default'])
->save();
// Create a vocabulary which is not enabled for scheduling. // Create a vocabulary which is not enabled for scheduling.
/** @var \Drupal\taxonomy\VocabularyInterface $nonSchedulerVocabulary */ /** @var \Drupal\taxonomy\VocabularyInterface $nonSchedulerVocabulary */
$this->nonSchedulerVocabulary = Vocabulary::create([ $this->nonSchedulerVocabulary = Vocabulary::create([
......