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

UHF-9135: Simplify mobile fallback menu #48

Merged
merged 12 commits into from
Oct 24, 2023
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
working-directory: ${{ env.DRUPAL_ROOT }}
run: |
composer config repositories.5 path $GITHUB_WORKSPACE
composer require drupal/$MODULE_NAME -W
composer require drupal/menu_block_current_language drupal/$MODULE_NAME -W
# We use COMPOSER_MIRROR_PATH_REPOS=1 to mirror local repository
# instead of symlinking it to prevent code coverage issues with
# phpunit. Copy .git folder manually so codecov can generate line by
Expand All @@ -71,8 +71,11 @@ jobs:

- name: Run PHPCS
working-directory: ${{ env.DRUPAL_ROOT }}
run: |
vendor/bin/phpcs $MODULE_FOLDER --standard=Drupal --extensions=php,module,inc,install,test,info
run: vendor/bin/phpcs $MODULE_FOLDER --standard=Drupal,DrupalPractice --extensions=php,module,install

- name: Run phpstan
working-directory: ${{ env.DRUPAL_ROOT }}
run: vendor/bin/phpstan analyze -c $MODULE_FOLDER/phpstan.neon $MODULE_FOLDER

- name: Start services
working-directory: ${{ env.DRUPAL_ROOT }}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"drupal/coder": "^8.3"
"drupal/coder": "^8.3",
"drupal/menu_block_current_language": "^2.0"
}
}
3 changes: 3 additions & 0 deletions helfi_navigation.install
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare(strict_types = 1);
use Drupal\block\Entity\Block;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\rest\Entity\RestResourceConfig;

/**
Expand Down Expand Up @@ -165,6 +166,8 @@ function _helfi_navigation_get_block_configuration() : array {
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function _helfi_navigation_generate_blocks(string $theme, ?string $region = NULL, bool $labelDisplay = FALSE) : void {
assert(\Drupal::languageManager() instanceof ConfigurableLanguageManagerInterface);

$default_config = [
'settings' => [
'label_display' => $labelDisplay,
Expand Down
10 changes: 7 additions & 3 deletions helfi_navigation.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

declare(strict_types = 1);

use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
Expand Down Expand Up @@ -169,6 +170,7 @@ function helfi_navigation_form_node_form_alter(
array &$form,
FormStateInterface $form_state
) :void {
assert($form_state->getFormObject() instanceof EntityFormInterface);
/** @var \Drupal\node\NodeInterface $node */
$node = $form_state->getFormObject()->getEntity();
$defaults = menu_ui_get_menu_link_defaults($node) + [
Expand Down Expand Up @@ -197,9 +199,11 @@ function helfi_navigation_form_node_form_alter(
/**
* A form submit callback for helfi_navigation_form_node_form_alter().
*/
function helfi_navigation_form_node_form_submit(array $form, FormStateInterface $formState) : void {
$values = $formState->getValue('menu');
$node = $formState->getFormObject()->getEntity();
function helfi_navigation_form_node_form_submit(array $form, FormStateInterface $form_state) : void {
assert($form_state->getFormObject() instanceof EntityFormInterface);

$values = $form_state->getValue('menu');
$node = $form_state->getFormObject()->getEntity();
$langCode = $node->language()->getId();

if (!empty($values['entity_id'])) {
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
fileExtensions:
- php
- module
- install
paths:
- ./
excludePaths:
- vendor
level: 3
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
2 changes: 1 addition & 1 deletion src/ApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function withBypassCache() : self {
* @param callable $callback
* The callback to handle requests.
*
* @return object|null
* @return \Drupal\helfi_navigation\CacheValue|null
* The cache or null.
*
* @throws \GuzzleHttp\Exception\GuzzleException
Expand Down
2 changes: 1 addition & 1 deletion src/MainMenuManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getSiteName(string $langcode) : string {
* @param string $langcode
* Language code.
*
* @return mixed
* @return array
* Menu tree.
*
* @throws \InvalidArgumentException
Expand Down
4 changes: 4 additions & 0 deletions src/Menu/MenuTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\TranslatableInterface;
use Drupal\Core\Menu\MenuLinkInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Menu\MenuLinkTreeElement;
Expand Down Expand Up @@ -287,6 +288,9 @@ private function evaluateEntityAccess(MenuLinkTreeElement $element, string $lang
return;
}

if (!$entity instanceof TranslatableInterface) {
return;
}
$entity = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity;

if (!$entity->access('view')) {
Expand Down
Loading
Loading