8 * Implements hook_admin_paths().
10 * Add all user-related pages to admin paths, which will make them use the
11 * admin theme, given the user has that permission.
13 function drop_jobs_admin_paths() {
21 * Implements hook_admin_paths_alter().
23 * A trick to enforce page refresh when theme is changed from an overlay.
25 function drop_jobs_admin_paths_alter(&$paths) {
26 $paths['admin/appearance/default*'] = FALSE
;
30 * Set Drop Jobs as default install profile.
32 * Must use system as the hook module because drop_jobs is not active yet
34 function system_form_install_select_profile_form_alter(&$form, $form_state) {
35 foreach($form['profile'] as
$key => $element) {
36 $form['profile'][$key]['#value'] = 'drop_jobs';
41 * Implements hook_form_FORM_ID_alter().
43 * Alter the site configuration form.
45 function drop_jobs_form_install_configure_form_alter(&$form, $form_state) {
46 // Many modules set messages during installation that are very annoying.
47 // Yeah, we're looking at you Date and iToggle.
48 // Let's clear these messages to avoid the false impression that something
49 // went wrong when it didn't.
50 drupal_get_messages('status');
51 drupal_get_messages('warning');
53 drupal_add_css(drupal_get_path('profile', 'drop_jobs') .
'/drop_jobs_install.css');
55 // Warn about settings.php permissions risk
56 $settings_dir = conf_path();
57 $settings_file = $settings_dir .
'/settings.php';
58 // Check that $_POST is empty so we only show this message when the form is
59 // first displayed, not on the next page after it is submitted. (We do not
60 // want to repeat it multiple times because it is a general warning that is
61 // not related to the rest of the installation process; it would also be
62 // especially out of place on the last page of the installer, where it would
63 // distract from the message that the Drupal installation has completed
65 if (empty($_POST) && (!drupal_verify_install_file(DRUPAL_ROOT .
'/' .
$settings_file, FILE_EXIST
| FILE_READABLE
| FILE_NOT_WRITABLE
) || !drupal_verify_install_file(DRUPAL_ROOT .
'/' .
$settings_dir, FILE_NOT_WRITABLE
, 'dir'))) {
66 drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the <a href="@handbook_url">online handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'warning');
69 // Pre-populate some fields.
70 $form['site_information']['site_name']['#default_value'] = 'Drop Jobs'; // We don't use t() intentionally.
71 $form['site_information']['site_mail']['#default_value'] = 'admin@' .
$_SERVER['HTTP_HOST'];
72 $form['admin_account']['account']['name']['#default_value'] = 'admin';
73 $form['admin_account']['account']['mail']['#default_value'] = 'admin@' .
$_SERVER['HTTP_HOST'];
75 // Add checkbox for example content.
76 $form['drop_jobs'] = array(
77 '#type' => 'fieldset',
78 '#collapsible' => FALSE
,
79 '#title' => t('Drop Jobs'),
82 $form['drop_jobs']['drop_jobs_demo_content'] = array(
83 '#type' => 'checkbox',
84 '#title' => t('Install demo content'),
85 '#description' => t('Check this option to enable demonstration content for Drop Jobs to get your site up and running quickly.'),
86 '#default_value' => TRUE
,
89 // Add select box for search provider.
90 $form['drop_jobs']['drop_jobs_search_provider'] = array(
92 '#title' => t('Search provider'),
93 '#description' => t("Apache Solr is recommended but if you don't have it available, things will break!. You might be better off installing with Database search, getting a Solr instance up and running and then switching to Solr search later using the Drop Jobs settings page."),
94 '#options' => drop_jobs_get_search_providers(),
95 '#default_value' => 'drop_jobs_solr',
98 // Add checkboxes for submodules.
99 $form['drop_jobs']['drop_jobs_features'] = array(
100 '#type' => 'fieldset',
101 '#title' => t('Features'),
102 '#description' => t('Enable additional Drop Jobs Features'),
103 '#collapsible' => FALSE
,
107 // Exclude core features.
108 $exclude = drop_jobs_core_features();
110 // Demo module gets special treatment so exclude it from this list.
111 $exclude[] = 'drop_jobs_demo';
113 // These are not so commonly used and get disabled by default.
118 // Add feature form items.
119 foreach (drop_jobs_get_features() as
$module => $info) {
120 // Exclude certain modules.
121 if (!in_array($module, $exclude)) {
122 $form['drop_jobs']['drop_jobs_features'][$module] = array(
123 '#type' => 'checkbox',
124 '#title' => $info->info
['name'],
125 '#description' => $info->info
['description'],
126 '#default_value' => !in_array($module, $disabled),
131 $form['#submit'][] = 'drop_jobs_install_configure_form_submit';
137 * Installs Drop Jobs demonstration content.
139 function drop_jobs_install_configure_form_submit(&$form, &$form_state) {
140 // Alias for convenience.
141 $values =& $form_state['values'];
143 // Enable additional modules.
144 if ($values['drop_jobs_features']) {
147 foreach ($values['drop_jobs_features'] as
$module => $modulesd) {
149 $modules[] = $module;
154 // Enable search provider.
155 $modules[] = $form_state['values']['drop_jobs_search_provider'];
157 // Set variable to enable additional modules.
158 variable_set('drop_jobs_install_extra_modules', $modules);
160 // Set variable to install or not demo content.
161 variable_set('drop_jobs_install_demo_content', $values['drop_jobs_demo_content']);
163 // For whatever reason we can't rely on roles always being created in the
164 // same order and receiving the same IDs, therefore find the role IDs and set
165 // them as variables we'll use throughout.
166 $employer_rid = reset(
167 db_select('role', 'r')
168 ->fields('r', array('rid'))
169 ->condition('name', DROP_JOBS_TYPE_EMPLOYER
, '=')
172 variable_set('drop_jobs_role_employer', $employer_rid);
174 $candidate_rid = reset(
175 db_select('role', 'r')
176 ->fields('r', array('rid'))
177 ->condition('name', DROP_JOBS_TYPE_CANDIDATE
, '=')
180 variable_set('drop_jobs_role_candidate', $candidate_rid);
183 db_select('role', 'r')
184 ->fields('r', array('rid'))
185 ->condition('name', 'administrator', '=')
188 variable_set('drop_jobs_role_admin', $admin_rid);
190 $webmaster_rid = reset(
191 db_select('role', 'r')
192 ->fields('r', array('rid'))
193 ->condition('name', 'webmaster', '=')
196 variable_set('drop_jobs_role_webmaster', $webmaster_rid);
200 * Implements hook_block_info().
202 function drop_jobs_block_info() {
204 'powered-by' => array(
205 'info' => t('Powered by Drop Jobs'),
207 'cache' => DRUPAL_CACHE_GLOBAL
,
213 * Implements hook_block_view().
215 function drop_jobs_block_view($delta = '') {
216 if ($delta === 'powered-by') {
219 'content' => '<span>' .
t('Powered by <a href="@drop_jobs">Drop Jobs</a>, a <a href="@drupal">Drupal</a> distribution by <a href="@alex">Alex</a> and <a href="@friends">friends</a>.', array('@drop_jobs' => 'http://drupal.org/project/drop_jobs', '@drupal' => 'http://drupal.org', '@alex' => 'http://alexweber.com.br', '@friends' => 'http://groups.drupal.org/drop-jobs-distribution')) .
'</span>',
225 * Returns an array of Drop Jobs modules (features) that are considered "core".
228 * An array of the core modules' machine names.
230 function drop_jobs_core_features() {
231 $core_features = array(
234 'drop_jobs_candidate',
235 'drop_jobs_employer',
237 'drop_jobs_organization',
240 // Allow list of core features to be altered.
241 drupal_alter('drop_jobs_core_features', $core_features);
243 return $core_features;
247 * Returns an array of Drop Jobs "Features" that can be turned on or off.
248 * These are Drop Jobs submodules, excluding those considered to be "core"
249 * by Drop Jobs or excluded by other modules.
252 * An array of available modules, keyed by machine name.
254 function drop_jobs_get_features() {
255 $core_features = drop_jobs_core_features();
257 // Add search providers to list of core features.
258 $search_providers = array_keys(drop_jobs_get_search_providers());
259 $filtered_features = array_merge($core_features, $search_providers);
261 // Build list of features.
264 foreach (system_rebuild_module_data() as
$module => $info) {
265 if (strpos($module, 'drop_jobs_') === 0 && !in_array($module, $filtered_features)) {
266 $features[$module] = $info;
274 * Returns a list of Drop Jobs Search providers that can be used.
277 * An array of available module names.
279 function drop_jobs_get_search_providers() {
280 $search_providers = &drupal_static(__FUNCTION__
, NULL
);
282 if (!isset($search_providers)) {
283 // Hard-coded because these are part of Drop Jobs Core.
284 $search_providers = array(
285 'drop_jobs_db' => t('Database search'),
286 'drop_jobs_solr' => t('Apache Solr'),
289 // Allow other modules to change this.
290 drupal_alter('drop_jobs_search_providers', $search_providers);
293 return $search_providers;
297 * Returns the active Drop Jobs Search provider.
299 function drop_jobs_search_provider() {
300 $providers = drop_jobs_get_search_providers();
301 $modules = module_list();
302 return array_intersect($modules, array_keys($providers));
306 * Implements hook_form_FORMID_alter().
308 * Adds a checkbox for controlling field view access to certain fields added to
309 * profiles and job nodes.
311 function drop_jobs_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
312 if ($form['instance']['entity_type']['#value'] == 'profile2' || ($form['instance']['entity_type']['#value'] === 'node' && $form['instance']['bundle']['#value'] === 'job')) {
313 // Add hidden field option.
314 $form['field']['settings']['drop_jobs_hidden'] = array(
315 '#type' => 'checkbox',
316 '#title' => t('Make the content of this field hidden.'),
317 '#default_value' => !empty($form['#field']['settings']['drop_jobs_hidden']),
318 '#description' => t('If checked, the content of this field is only shown to administrators.'),
321 // Change Profile2 private field description.
322 if (isset($form['field']['settings']['profile2_private'])) {
323 $form['field']['settings']['profile2_private']['#description'] = t('If checked, the content of this field is only shown to the profile owner, administrators and employers with active subscriptions.');
327 // Add the value to the form so it isn't lost.
328 $form['field']['settings']['drop_jobs_hidden'] = array(
330 '#value' => !empty($form['#field']['settings']['drop_jobs_hidden']),
336 * Implements hook_field_access().
338 function drop_jobs_field_access($op, $field, $entity_type, $entity = NULL
, $account = NULL
) {
340 && ($entity_type == 'profile2'
341 || ($entity_type === 'node' && isset($entity)
342 && $entity->type
=== 'job'))
343 && !empty($field['settings']['drop_jobs_hidden'])
344 && !user_access('administer drop_jobs', $account)) {
350 * Determine whether a user has a particular role.
351 * If no user is specified we use the current user.
354 * The role, can be either the numeric id or the machine name.
356 * The user, if none is specified checks against the current user.
358 * TRUE if the user has that role, FALSE otherwise.
360 function drop_jobs_user_has_role($rid, $uid = NULL
) {
361 $user = user_uid_optional_load($uid);
363 // Make sure we have a valid user object.
364 if (is_object($user) && isset($user->roles
) && is_array($user->roles
)) {
365 return (is_numeric($rid)) ?
in_array($rid, array_keys($user->roles
)) : in_array($rid, $user->roles
);