Created
October 6, 2016 07:29
-
-
Save init90/e55dba4d3bee12f0507e217a54c1c4fd to your computer and use it in GitHub Desktop.
Drupal, change front page by user role.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_preprocess_block(&$variables). | |
*/ | |
function icareix_global_preprocess_block(&$variables) { | |
if ($variables['elements']['#plugin_id'] == 'system_branding_block') { | |
// Select front page by user role. | |
$current_user = \Drupal::currentUser(); | |
$current_uid = $current_user->id(); | |
$config = \Drupal::config('icareix_global.FrontPageByRole'); | |
$url = \Drupal::config('system.site')->get('page.front'); | |
$url = \Drupal\Core\Url::fromUserInput($url, ['absolute' => TRUE])->toString(); | |
if ($current_user->hasPermission('job_admin') && $current_uid != 1) { | |
if ($config_url = $config->get('for_job_admin')) { | |
$url = \Drupal\Core\Url::fromUserInput($config_url, ['absolute' => TRUE])->toString(); | |
} | |
} | |
elseif ($current_user->hasPermission('available for hire') && $current_uid != 1) { | |
if ($config_url = $config->get('for_care_giver')) { | |
$url = \Drupal\Core\Url::fromUserInput($config_url, ['absolute' => TRUE]); | |
$url = $url->toString(); | |
} | |
} | |
elseif ($current_user->hasPermission('receiver') && $current_uid != 1) { | |
$job = Drupal::entityTypeManager() | |
->getStorage('job') | |
->loadByProperties(['field_care_receiver' => $current_uid]); | |
if ($job) { | |
$job_id = current($job)->id(); | |
$url = \Drupal\Core\Url::fromUserInput("/job/$job_id", ['absolute' => TRUE])->toString(); | |
} | |
else { | |
if ($config_url = $config->get('for_care_receiver')) { | |
$url = \Drupal\Core\Url::fromUserInput($config_url, ['absolute' => TRUE])->toString(); | |
} | |
} | |
} | |
$variables['content']['front_page'] = $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment