You are here

function theme_icon_bundle_overview_form in Icon API 8

Same name and namespace in other branches
  1. 7 includes/admin.inc \theme_icon_bundle_overview_form()

Theme implementation for 'icon_bundle_overview_form'.

File

includes/admin.inc, line 156
admin.inc Provides administrative callbacks and tasks.

Code

function theme_icon_bundle_overview_form($variables) {
  $output = '';
  $form = $variables['form'];
  $admin = \Drupal::currentUser()
    ->hasPermission('administer icons');
  $header = array(
    'enable' => t('Enabled'),
    'bundle' => t('Bundle'),
    'count' => t('Count'),
    'provider' => t('Provider'),
    'operations' => t('Operations'),
  );

  // Remove the "Enabled" header for non-admin users.
  if (!$admin) {
    array_shift($header);
  }
  $rows = array();
  foreach (\Drupal\Core\Render\Element::children($form['bundles']) as $key) {
    $bundle = $form['bundles'][$key]['#bundle'];
    $row = array();
    if ($admin) {
      $row['status'] = array(
        'data' => \Drupal::service("renderer")
          ->render($form['bundles'][$key]['status']),
        'class' => 'compact center',
      );
    }
    $row['bundle'] = $bundle['title'] . (!empty($bundle['version']) ? ' - ' . $bundle['version'] : '');
    $row['count'] = array(
      'data' => count($bundle['icons']),
      'class' => 'compact center',
    );
    $row['provider']['class'] = 'compact nowrap';
    if ($provider = icon_provider_load($bundle['provider'])) {

      // @FIXME
      // l() expects a Url object, created from a route name or external URI.
      // $row['provider']['data'] = !empty($provider['url']) ? l($provider['title'], $provider['url']) : $provider['title'];
    }
    else {
      $row['provider']['data'] = $bundle['provider'];
    }

    // Build operations for each bundle.
    $row['operations'] = array(
      'class' => 'compact nowrap',
    );
    $operations = array();
    if ($bundle['status']) {
      $operations['view'] = array(
        'title' => '<i class="iconapi-view"></i>' . t('View Icons'),
        'href' => ($admin && arg(0) === 'admin' ? ICON_ADMIN_PATH . '/bundle/' : \Drupal::config('icon.settings')
          ->get('icon_api_view_path_alias') . '/') . $bundle['name'],
        'html' => TRUE,
      );
      if ($admin) {
        $operations['configure'] = array(
          'title' => '<i class="iconapi-configure"></i>' . t('Configure'),
          'href' => ICON_ADMIN_PATH . '/bundle/' . $bundle['name'] . '/configure',
          'html' => TRUE,
        );
      }
    }
    if ($admin && !empty($bundle['import'])) {
      $operations['delete'] = array(
        'title' => '<i class="iconapi-delete"></i>' . t('Delete'),
        'href' => ICON_ADMIN_PATH . '/bundle/' . $bundle['name'] . '/delete',
        'html' => TRUE,
      );
    }
    elseif ($admin && !empty($bundle['overridden'])) {
      $operations['reset'] = array(
        'title' => '<i class="iconapi-throbber"></i>' . t('Reset'),
        'href' => ICON_ADMIN_PATH . '/bundle/' . $bundle['name'] . '/reset',
        'html' => TRUE,
      );
    }
    if (!empty($operations)) {
      $row['operations']['data'] = array(
        '#theme' => 'links',
        '#links' => $operations,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      );
    }
    $rows[] = $row;
  }

  // @FIXME
  // theme() has been renamed to _theme() and should NEVER be called directly.
  // Calling _theme() directly can alter the expected output and potentially
  // introduce security issues (see https://www.drupal.org/node/2195739). You
  // should use renderable arrays instead.
  //
  //
  // @see https://www.drupal.org/node/2195739
  // $output .= theme('table', array(
  //     'header' => $header,
  //     'rows' => $rows,
  //     'empty' => t('No bundles are currently installed.'),
  //   ));
  $output .= drupal_render_children($form);
  return $output;
}