Skip to content

Commit

Permalink
feat(SHS-6009): Hide block visibility and region fields from non-deve…
Browse files Browse the repository at this point in the history
…lopers on social media block
  • Loading branch information
codechefmarc committed Jan 13, 2025
1 parent a511954 commit 09f302a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docroot/modules/humsci/hs_blocks/hs_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ function hs_blocks_form_layout_builder_add_block_alter(&$form, FormStateInterfac
}
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function hs_blocks_form_block_form_alter(&$form, FormStateInterface $form_state) {
$block_form = $form_state->getFormObject();
/** @var Drupal\block\BlockForm $block_form */
$block = $block_form->getEntity();
// Hide block visibility and region fields from non-developers.
if ($block instanceof Block && $block->getPluginId() == 'hs_blocks_social_media_block') {
/** @var Drupal\Entity\User $current_user */
$current_user = \Drupal::currentUser();
if (!$current_user->hasRole('administrator')) {
$form['visibility']['#access'] = FALSE;
$form['region']['#access'] = FALSE;
}
}
}

/**
* Implements hook_preprocess_HOOK().
*/
Expand Down

0 comments on commit 09f302a

Please sign in to comment.