diff --git a/modules/tide_media/tide_media.module b/modules/tide_media/tide_media.module index 9ee7eaf48..9224cb48f 100644 --- a/modules/tide_media/tide_media.module +++ b/modules/tide_media/tide_media.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Render\FormattableMarkup; +use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -16,6 +17,7 @@ use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\file\FileInterface; use Drupal\views\ViewExecutable; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Implements hook_views_pre_view(). @@ -152,6 +154,17 @@ function tide_media_form_media_form_alter(&$form, FormStateInterface $form_state * Implements template_preprocess_field(). */ function tide_media_preprocess_field(&$variables) { + $route_name = \Drupal::routeMatch()->getRouteName(); + $current_user = \Drupal::currentUser(); + $roles = $current_user->getRoles(); + + if ($route_name === 'entity.user.edit_form' && in_array('secure_file_user', $roles)) { + $url = \Drupal\Core\Url::fromRoute('entity.user.canonical', ['user' => $current_user->id()]); + $response = new RedirectResponse($url->toString()); + $response->send(); + exit(); + } + if ($variables['field_name'] == 'field_media_file') { $element = $variables['element']; if ($element['#entity_type'] == 'media' && $element['#bundle'] == 'document' && $element['#view_mode'] == 'embedded') { @@ -464,3 +477,19 @@ function tide_media_file_presave(FileInterface $file) { $file->setFilename($filename_new); } } + +/** + * Implements hook_menu_local_tasks_alter(). + */ +function tide_media_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) { + $current_user = \Drupal::currentUser(); + $roles = $current_user->getRoles(); + + if (in_array('secure_file_user', $roles)) { + foreach ($data['tabs'][0] as $key => $items) { + if ($key === 'entity.user.edit_form') { + unset($data['tabs'][0][$key]); + } + } + } +}