You are here

function node_limit_list_limits in Node Limit 8

Same name and namespace in other branches
  1. 6 node_limit.module \node_limit_list_limits()
  2. 7 node_limit.module \node_limit_list_limits()

Form for listing the created limits.

Created as a form so that the user can adjust the weight.

1 string reference to 'node_limit_list_limits'
node_limit_menu in old/node_limit.module
Implements hook_menu().

File

old/node_limit.module, line 352

Code

function node_limit_list_limits() {
  $weights = array();
  for ($i = -10; $i <= 10; $i++) {
    $weights[$i] = $i;
  }
  $form = array(
    '#tree' => TRUE,
  );
  $form['limits'] = array();
  $query = \Drupal::database()
    ->select('node_limit', 'nl')
    ->fields('nl')
    ->orderBy('weight', 'ASC')
    ->execute();
  $nlimit = 0;
  foreach ($query as $row) {
    $nlimit++;
    $form['limits'][$row->lid]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => $row->weight,
    );
    $form['limits'][$row->lid]['title'] = array(
      '#markup' => check_plain($row->title),
    );
    $form['limits'][$row->lid]['limit'] = array(
      '#markup' => check_plain($row->nlimit),
    );
    $form['limits'][$row->lid]['edit'] = array(
      '#type' => 'link',
      '#title' => t('Edit'),
      '#href' => 'admin/structure/node_limit/' . $row->lid,
    );
    $form['limits'][$row->lid]['list'] = array(
      '#type' => 'link',
      '#title' => t('Delete'),
      '#href' => 'admin/structure/node_limit/' . $row->lid . '/delete',
    );
    $form['limits'][$row->lid]['clone'] = array(
      '#type' => 'link',
      '#title' => t('Clone'),
      '#href' => 'admin/structure/node_limit/' . $row->lid . '/clone',
    );
  }
  if ($nlimit > 0) {
    $form['save'] = array(
      '#type' => 'submit',
      '#value' => t('Save Limits'),
    );
  }
  else {
    $form['create'] = array(
      '#type' => 'link',
      '#title' => t('Add a new node limit'),
      '#href' => 'admin/structure/node_limit/add',
    );
  }
  return $form;
}