Skip to content

Commit

Permalink
Merge pull request #1171 from UN-OCHA/release-versions/v1.12.1
Browse files Browse the repository at this point in the history
release versions/v1.12.1
  • Loading branch information
berliner authored Nov 11, 2024
2 parents 00e96ca + 1c9c92b commit 3a32087
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public function buildTableData($export = FALSE) {
],
];
if ($export) {
$header['in_gho'] = $this->t('In GHO');
$header['document'] = [
'data' => $this->t('Document'),
'data-column-type' => 'document',
Expand Down Expand Up @@ -282,7 +283,7 @@ public function buildTableData($export = FALSE) {
$rows[$plan->id()] = [];

if ($export) {
$rows[$plan->id()]['plan_id'] = ['data' => $plan_entity?->id()];
$rows[$plan->id()]['plan_id'] = ['data' => $plan->id()];
}

$rows[$plan->id()] += [
Expand All @@ -293,6 +294,7 @@ public function buildTableData($export = FALSE) {
],
],
'data-value' => $plan->getName(),
'data-raw-value' => $plan->getName(),
],
'type' => [
'data' => [
Expand Down Expand Up @@ -393,6 +395,7 @@ public function buildTableData($export = FALSE) {
],
];
if ($export) {
$rows[$plan->id()]['in_gho'] = $plan->isPartOfGho() ? $this->t('Yes') : $this->t('No');
$rows[$plan->id()]['document'] = [
'data' => $document_uri,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected function setUp(): void {
'layout_density' => 'default',
'show_description_toggle' => FALSE,
'show_user_theme_settings' => FALSE,
'sticky_action_buttons' => TRUE,
])
->save();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ protected function alterRoutes(RouteCollection $collection) {
$wizard_route->setRequirement('_entity_create_access', 'node:article');
$wizard_route->setDefault('_form', '\Drupal\ghi_content\Form\ArticleWizard');
$wizard_route->setDefault('node_type', ArticleManager::ARTICLE_BUNDLE);
$wizard_route->setOption('_node_operation_route', TRUE);
$collection->add('ghi_content.wizard.article', $wizard_route);

$wizard_route = clone $route;
$wizard_route->setPath('node/add/' . DocumentManager::DOCUMENT_BUNDLE);
$wizard_route->setRequirement('_entity_create_access', 'node:document');
$wizard_route->setDefault('_form', '\Drupal\ghi_content\Form\DocumentWizard');
$wizard_route->setDefault('node_type', DocumentManager::DOCUMENT_BUNDLE);
$wizard_route->setOption('_node_operation_route', TRUE);
$collection->add('ghi_content.wizard.document', $wizard_route);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ private function renderDomNode(\DOMNode $node) {
// PHP DOMElement don't have a innerHTML property so this is the current way
// of getting it.
// @see https://bugs.php.net/bug.php?id=44762
return implode('', array_map(function ($child) {
return $child->ownerDocument->saveXML($child);
return implode('', array_map(function (\DOMNode $child) {
return mb_convert_encoding($child->ownerDocument->saveXML($child), 'ISO-8859-1');
}, iterator_to_array($node->childNodes)));
}

Expand Down
7 changes: 7 additions & 0 deletions html/modules/custom/ghi_homepage/ghi_homepage.module
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ function ghi_homepage_preprocess_page(&$variables) {

$variables['page']['help'] = ['message' => $message];
}

/**
* Implements hook_gin_ignore_sticky_form_actions_alter().
*/
function ghi_homepage_gin_ignore_sticky_form_actions_alter(&$form_ids) {
$form_ids[] = 'ghi_homepage_wizard';
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function alterRoutes(RouteCollection $collection) {
$wizard_route->setRequirement('_entity_create_access', 'node:' . Homepage::BUNDLE);
$wizard_route->setDefault('_form', '\Drupal\ghi_homepage\Form\HomepageWizard');
$wizard_route->setDefault('node_type', Homepage::BUNDLE);
$wizard_route->setOption('_node_operation_route', TRUE);
$collection->add('ghi_homepage.wizard.homepage', $wizard_route);
}
}
Expand Down
4 changes: 4 additions & 0 deletions html/modules/custom/ghi_homepage/src/Form/HomepageWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function buildForm(array $form, FormStateInterface $form_state, ?NodeInte
];
}

$form['actions'] = [
'#type' => 'actions',
];

if ($step > 0) {
$form['actions']['back'] = [
'#type' => 'button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

namespace Drupal\Tests\ghi_homepage\Functional;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;
use Drupal\Tests\ghi_base_objects\Traits\BaseObjectTestTrait;
use Drupal\Tests\ghi_base_objects\Traits\FieldTestTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\ghi_homepage\Entity\Homepage;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Tests the node wizard pages.
*
* @group ghi_sections
* @group ghi_homepage
*/
class WizardTest extends BrowserTestBase {

Expand All @@ -29,34 +32,102 @@ class WizardTest extends BrowserTestBase {
* @var array
*/
protected static $modules = [
'gin_lb',
'ghi_homepage',
];

/**
* Declare modules that the used theme depends on.
*
* @var array
*/
protected static $themeDependencies = [
'gin_lb',
];

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
protected $defaultTheme = 'common_design_subtheme';

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->assertTrue(\Drupal::service('theme_installer')->install(['gin']));
$this->container->get('config.factory')
->getEditable('system.theme')
->set('default', 'common_design_subtheme')
->set('admin', 'gin')
->save();

$this->container->get('config.factory')
->getEditable('node.settings')
->set('use_admin_theme', TRUE)
->save();

$this->container->get('config.factory')
->getEditable('gin.settings')
->merge([
'preset_accent_color' => 'custom',
'preset_focus_color' => 'gin',
'enable_darkmode' => '0',
'classic_toolbar' => 'horizontal',
'secondary_toolbar_frontend' => FALSE,
'high_contrast_mode' => FALSE,
'accent_color' => '#4D4D4D',
'focus_color' => '',
'layout_density' => 'default',
'show_description_toggle' => FALSE,
'show_user_theme_settings' => FALSE,
'sticky_action_buttons' => TRUE,
])
->save();

$this->setupContent();

// Create a user with permission to view the actions administration pages.
// Create a user with permission to view the administration pages.
$this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'administer themes',
'access toolbar',
'access administration pages',
'administer nodes',
'bypass node access',
'view the administration theme',
]));

\Drupal::service('router.builder')->rebuildIfNeeded();
}

/**
* {@inheritdoc}
*/
protected function installDefaultThemeFromClassProperty(ContainerInterface $container) {
// We install the theme dependencies first, otherwhise our custom theme
// refuses to install.
$modules = static::$themeDependencies;
$success = $container->get('module_installer')->install($modules, TRUE);
$this->assertTrue($success, new FormattableMarkup('Enabled modules: %modules', ['%modules' => implode(', ', $modules)]));

// And we need to clear the config cache so that the theme installer is
// aware of the newly installed modules.
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $container->get('config.factory');
$config_factory->clearStaticCache();

parent::installDefaultThemeFromClassProperty($container);
}

/**
* Tests homepage wizard page.
*/
public function testHomepageWizard() {
$this->drupalGet('/node/add/homepage');
$this->drupalGet('/admin/appearance');

$this->drupalGet('/node/add/' . Homepage::BUNDLE);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('No teams found. You must import teams before sections can be created.');
$this->assertSession()->pageTextContains('Create Homepage');
Expand Down Expand Up @@ -91,13 +162,13 @@ public function testHomepageUniquePerYear() {
])->save();

Node::create([
'type' => 'homepage',
'type' => Homepage::BUNDLE,
'title' => '2023',
'field_year' => '2023',
'field_team' => $team,
])->save();

$this->drupalGet('/node/add/homepage');
$this->drupalGet('/node/add/' . Homepage::BUNDLE);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->fieldExists('Year');
$this->assertSession()->buttonExists('Next');
Expand All @@ -118,11 +189,11 @@ public function testHomepageUniquePerYear() {
*/
private function setupContent() {
$this->drupalCreateContentType([
'type' => 'homepage',
'type' => Homepage::BUNDLE,
'name' => 'Homepage',
]);

$this->createField('node', 'homepage', 'integer', 'field_year', 'Year');
$this->createField('node', Homepage::BUNDLE, 'integer', 'field_year', 'Year');

// Create team vocabulary and fields.
Vocabulary::create([
Expand All @@ -134,7 +205,7 @@ private function setupContent() {
'team' => 'team',
],
];
$this->createEntityReferenceField('node', 'homepage', 'field_team', 'Team', 'taxonomy_term', 'default', $handler_settings);
$this->createEntityReferenceField('node', Homepage::BUNDLE, 'field_team', 'Team', 'taxonomy_term', 'default', $handler_settings);
Term::create([
'name' => $this->randomMachineName(),
'vid' => 'team',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public function getSupportedPrototypeIds() {
if (empty($this->can_support)) {
return [];
}
$can_support = array_filter($this->can_support, function ($item) {
// The value of can support is either an array or some kind of logical
// wrapper object. We need an array, so if it's an object, let's see if
// it's one we know, like xor, and then get it's sub items as an array.
$can_support = is_array($this->can_support) ? $this->can_support : (is_object($this->can_support) && property_exists($this->can_support, 'xor') ? $this->can_support->xor : []);
$can_support = array_filter($can_support, function ($item) {
// Ignore items that are not objects, it's probably an "xor" thing that
// we don't want to handle at the moment.
return is_object($item) && property_exists($item, 'id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function alterRoutes(RouteCollection $collection) {
$wizard_route->setRequirement('_entity_create_access', 'node:' . Section::BUNDLE);
$wizard_route->setDefault('_form', '\Drupal\ghi_sections\Form\SectionWizard');
$wizard_route->setDefault('node_type', Section::BUNDLE);
$wizard_route->setOption('_node_operation_route', TRUE);
$collection->add('ghi_sections.wizard.section', $wizard_route);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function alterRoutes(RouteCollection $collection) {
$wizard_route->setRequirement('_entity_create_access', 'node:' . CustomSubpageManager::BUNDLE);
$wizard_route->setDefault('_form', '\Drupal\ghi_subpages_custom\Form\CustomSubpageWizard');
$wizard_route->setDefault('node_type', CustomSubpageManager::BUNDLE);
$wizard_route->setOption('_node_operation_route', TRUE);
$collection->add('ghi_subpages_custom.wizard.custom_subpage', $wizard_route);
}
}
Expand Down

0 comments on commit 3a32087

Please sign in to comment.