Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0.4'
Browse files Browse the repository at this point in the history
release/2.0.4
  • Loading branch information
Mayur Gondhkar committed Jun 1, 2021
2 parents 1c45464 + 4dc43f5 commit 7f219c8
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 8 deletions.
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
"type": "composer",
"url": "https://packages.drupal.org/8"
}
},
"extra": {
"drush": {
"services": {
"drush.services.yml": "^10"
}
}
}
}
5 changes: 5 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
tide_site.commands:
class: \Drupal\tide_site\Commands\TideSiteCommands
tags:
- { name: drush.command }
57 changes: 57 additions & 0 deletions src/Commands/TideSiteCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Drupal\tide_site\Commands;

use Drush\Commands\DrushCommands;

/**
* A Drush commandfile.
*
* In addition to this file, you need a drush.services.yml
* in root of your module, and a composer.json file that provides the name
* of the services file to use.
*
* See these files for an example of injecting Drupal services:
* - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
* - http://cgit.drupalcode.org/devel/tree/drush.services.yml
*/
class TideSiteCommands extends DrushCommands {

/**
* Update the domains on the site taxonomy based on an environment variable.
*
* @usage drush tide-site-env-domain-update
* Update the domains on the site taxonomy based on an environment variable.
*
* @command tide:site-env-domain-update
* @aliases tide-si-domup,tide-site-env-domain-update
* @throws \Exception
*/
public function siteEnvDomainUpdate() {
try {
$environment = getenv('LAGOON_GIT_BRANCH');
if ($environment == 'production') {
$this->output()->writeln(t('This command cannot run in Lagoon production environments.'));
}
else {
$fe_domains = getenv('FE_DOMAINS');
if (!empty($fe_domains)) {
foreach (explode(',', $fe_domains) as $fe_domain) {
$domain = explode('|', $fe_domain);
$term = Term::load($domain[0]);
$term->set('field_site_domains', str_replace('<br/>', "\r\n", $domain[1]));
$term->save();
}
$this->output()->writeln(t('Domains Updated.'));
}
else {
$this->output()->writeln(t('No site specific domains were found in this environment.'));
}
}
}
catch (ConsoleException $exception) {
throw new \Exception($exception->getMessage());
}
}

}
9 changes: 4 additions & 5 deletions src/TideSiteMenuAutocreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\tide_site;

use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
Expand Down Expand Up @@ -228,7 +227,7 @@ protected function getAssociatedMenu($menu_title, $tid) {
*/
protected static function filterAutocreateFieldNames($values) {
return array_filter($values, function ($k) {
return Unicode::strpos($k, self::AUTOCREATE_FIELD_PREFIX) === 0 && Unicode::strpos($k, 'menu') !== FALSE;
return mb_strpos($k, self::AUTOCREATE_FIELD_PREFIX) === 0 && mb_strpos($k, 'menu') !== FALSE;
}, ARRAY_FILTER_USE_KEY);
}

Expand All @@ -252,11 +251,11 @@ protected static function makeAutocreateFieldName($string) {
* If provided string does not contain expected field prefix.
*/
protected static function extractMenuName($string) {
if (Unicode::strpos($string, self::AUTOCREATE_FIELD_PREFIX) === FALSE) {
if (mb_strpos($string, self::AUTOCREATE_FIELD_PREFIX) === FALSE) {
throw new \Exception('Unable to extract menu name from provided value');
}

return Unicode::substr($string, Unicode::strlen(self::AUTOCREATE_FIELD_PREFIX));
return mb_substr($string, mb_strlen(self::AUTOCREATE_FIELD_PREFIX));
}

/**
Expand Down Expand Up @@ -350,7 +349,7 @@ protected function makeMenuLabel($menu_title, $tid) {
*/
protected static function toMachineName($string, $delimiter = '_') {
$string = trim($string);
$string = Unicode::strtolower($string);
$string = mb_strtolower($string);
// Replace spaces and hyphens, preserving existing delimiters.
$string = str_replace([$delimiter, ' ', '-', '_'], $delimiter, $string);
// Remove all other non-alphanumeric characters.
Expand Down
3 changes: 1 addition & 2 deletions tests/src/Unit/TideSiteFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class TideSiteFieldsTest extends TideSiteTest {
* @dataProvider providerNormaliseFieldName
*/
public function testToMachineName($field_name, $entity_type_id, $bundle, $expected) {
$mock = self::createMock('Drupal\tide_site\TideSiteFields');
$actual = $this->callProtectedMethod($mock, 'normaliseFieldName', [$field_name, $entity_type_id, $bundle]);
$actual = TideSiteFields::normaliseFieldName($field_name, $entity_type_id, $bundle);
$this->assertEquals($expected, $actual);
}

Expand Down
29 changes: 28 additions & 1 deletion tide_site.module
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function tide_site_tide_path_enhancer_transform_alter(&$value, &$context) {
* Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
*/
function tide_site_form_node_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\node\Entity\Node $node */
/** @var \Drupal\node\NodeInterface $node */
$node = $form_state->getFormObject()->getEntity();
$form['tide_site_path_settings'] = [
'#type' => 'details',
Expand Down Expand Up @@ -443,6 +443,33 @@ function tide_site_form_node_form_alter(&$form, FormStateInterface $form_state)
}
}

// Move site fields to a Sidebar tab.
$form['tide_site_metadata'] = [
'#type' => 'details',
'#title' => t('Sites'),
'#open' => $node->isNew(),
'#optional' => TRUE,
'#access' => TRUE,
'#group' => 'advanced',
'#attributes' => [
'class' => ['tide-site-metadata'],
],
'#weight' => 100,
];

$site_fields = [
0 => TideSiteFields::normaliseFieldName(TideSiteFields::FIELD_PRIMARY_SITE, 'node'),
10 => TideSiteFields::normaliseFieldName(TideSiteFields::FIELD_SITE, 'node'),
];
foreach ($site_fields as $weight => $site_field) {
if ($node->hasField($site_field)) {
if (isset($form[$site_field])) {
$form[$site_field]['#group'] = 'tide_site_metadata';
$form[$site_field]['#weight'] = $weight;
}
}
}

// Adds our #after_build callback.
$form['#after_build'][] = 'tide_site_form_node_form_after_build';
}
Expand Down

0 comments on commit 7f219c8

Please sign in to comment.