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

VACMS-15222: Unlock benefit taxonomy fields to content admins #15273

Merged
merged 2 commits into from
Sep 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Drupal\va_gov_benefits\EventSubscriber;

use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
use Drupal\core_event_dispatcher\FormHookEvents;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\va_gov_user\Service\UserPermsService;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
use Drupal\core_event_dispatcher\FormHookEvents;
use Drupal\va_gov_user\Service\UserPermsService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -65,14 +65,19 @@ public function formAlter(FormAlterEvent $event): void {
*/
public function protectSelectFields(array &$form, FormStateInterface $form_state): void {
$form_object = $form_state->getFormObject();
if ($form_object instanceof ContentEntityForm) {
$bundle = $form_object->getEntity()->bundle();
if (!$this->userPermsService->hasAdminRole(TRUE) && $bundle === 'va_benefits_taxonomy') {
// Disable Official Benefit name field from non-editors.
if ($form_object instanceof ContentEntityForm
&& $form_object->getEntity()->bundle() === 'va_benefits_taxonomy') {
// Distinguish between admins and lock down accordingly.
$is_admin = $this->userPermsService->hasAdminRole();
$is_administrator_only = $this->userPermsService->hasAdminRole(TRUE);
if (!$is_admin) {
// Disable Official Benefit name field from non-admins.
$form['name']['#disabled'] = TRUE;
// Hide API ID field from non-editors.
$form['field_va_benefit_api_id']['#access'] = FALSE;
// Hide taxonomy Relations field from non-editors.
// Disable API ID field from non-admins.
$form['field_va_benefit_api_id']['#disabled'] = TRUE;
}
if (!$is_administrator_only) {
// Hide taxonomy Relations field.
$form['relations']['#access'] = FALSE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Feature: Taxonomy: VA Benefits
When I am at "admin/structure/taxonomy/manage/va_benefits_taxonomy/add"
Then I should see "Official Benefit name"
And I should see "The full name of the benefit."
And an element with the selector "#edit-name-0-value" should be disabled
And an element with the selector "#edit-field-va-benefit-api-id-0-value" should not exist
And an element with the selector "#edit-name-0-value" should not be disabled
And an element with the selector "#edit-field-va-benefit-api-id-0-value" should exist
And an element with the selector "#edit-relations" should not exist

Scenario: Log in and create a va benefit.
Expand Down