You are here

function drop_down_login_block_view in Drop Down Login 7

Implements hook_block_view().

File

./drop_down_login.module, line 44
Module file for Drop Down Login.

Code

function drop_down_login_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'drop_down_login':
      global $theme;
      $bootstrap_template = variable_get('drop_down_login_bootstrap_theme');
      $bootstrap_theme = theme_get_setting('bootstrap_image_responsive', $theme);
      if (isset($bootstrap_template) && !empty($bootstrap_template) && isset($bootstrap_theme) && !empty($bootstrap_theme)) {
        $drop_down_myaccount = 'drop_down_bootstrap_myaccount';
        $drop_down_logout = 'drop_down_bootstrap_logout';
        $drop_down_login = 'drop_down_bootstrap_login';
      }
      else {
        $drop_down_myaccount = 'drop_down_myaccount';
        $drop_down_logout = 'drop_down_logout';
        $drop_down_login = 'drop_down_login';
      }
      if (user_is_anonymous()) {

        // Variables for login.
        // Block login form.
        $login_form = drupal_get_form('user_login_block');
        $login_url = url('user');
        $login_link_text = variable_get('login_text', t('Login'));
        $block['content']['#markup'] = theme($drop_down_login, array(
          'login_form' => $login_form,
          'login_url' => $login_url,
          'login_link_text' => $login_link_text,
        ));
      }
      else {

        // Check drop down login settings.
        global $user;
        $profile_pic = variable_get('drop_down_login_profile_pic');
        $myaccount = variable_get('drop_down_login_want_myaccount');
        $account_text = variable_get('my_account_text', t('My Account'));

        // Required my account drop down.
        if (isset($profile_pic) && isset($user->picture) && !empty($user->picture) && !empty($profile_pic)) {
          $profile_load = file_load($user->picture);
          $profile_image = image_style_url('thumbnail', $profile_load->uri);
        }
        if (isset($myaccount) && !empty($myaccount)) {
          $myaccount_links = array();
          $myaccount_url = url('user');
          $myaccount_text = $account_text;
          $myaccount_link = variable_get('drop_down_login_myaccount_links', array());
          foreach ($myaccount_link as $key => $value) {

            // If <front> is used as a menu url in configuration.
            if ($value['menu']['menu_url'] == '<front>') {
              $myaccount_links[$key] = $value;
              $myaccount_links[$key]['menu']['menu_url'] = variable_get('site_frontpage', 'node');
            }
            else {
              $router_item = menu_get_item($value['menu']['menu_url']);
              if ($router_item = menu_get_item($value['menu']['menu_url'])) {
                if ($router_item['access']) {
                  $myaccount_links[$key] = $value;
                }
              }
            }
          }

          // Sort links by weight.
          if (!empty($myaccount_links)) {
            usort($myaccount_links, function ($a, $b) {
              return $a['weight'] - $b['weight'];
            });
          }
          $block['content']['#markup'] = theme($drop_down_myaccount, array(
            'myaccount_links' => !empty($myaccount_links) ? $myaccount_links : NULL,
            'myaccount_url' => $myaccount_url,
            'myaccount_text' => $myaccount_text,
            'account' => $user,
            'profile_image' => isset($profile_image) ? $profile_image : '',
          ));
        }
        else {

          // Variables for Logout.
          $logout_url = url('user/logout');
          $logout_link_text = variable_get('logout_text', t('Logout'));
          $block['content']['#markup'] = theme($drop_down_logout, array(
            'logout_url' => $logout_url,
            'logout_link_text' => $logout_link_text,
          ));
        }
      }
      break;
  }

  // Attching required js and css.
  $block['content']['#attached'] = array(
    'css' => array(
      drupal_get_path('module', 'drop_down_login') . '/theme/drop_down_login.css',
    ),
    'js' => array(
      drupal_get_path('module', 'drop_down_login') . '/theme/drop_down_login.js',
    ),
  );
  return $block;
}