diff --git a/node_limit.module b/node_limit.module index 28ee047..48c48fa 100644 --- a/node_limit.module +++ b/node_limit.module @@ -2,7 +2,7 @@ /** * @file - * Contains node_limit.module + * Contains node_limit.module. */ use Drupal\Core\Routing\RouteMatchInterface; @@ -10,9 +10,7 @@ use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_help(). */ - -function node_limit_help($route_name, RouteMatchInterface $route_match) -{ +function node_limit_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { // Main module help for the node_limit module. case 'help.page.node_limit': @@ -20,16 +18,13 @@ function node_limit_help($route_name, RouteMatchInterface $route_match) $output .= '

' . t('About') . '

'; $output .= '

' . t('Allows admins to restrict the number of nodes that may be created.') . '

'; return $output; - break; } } /** * Implements hook_theme(). */ - -function node_limit_theme() -{ +function node_limit_theme() { $theme = []; return $theme; diff --git a/old/node_limit.api.php b/old/node_limit.api.php index b14cfdc..13b7492 100644 --- a/old/node_limit.api.php +++ b/old/node_limit.api.php @@ -1,4 +1,5 @@ condition('lid', $lids, 'IN') ->execute(); @@ -54,16 +56,17 @@ function hook_node_limit_delete($lids) { /** * Return submodules' form elements. - * - * You may set the value '#custom_render' => true if your element requires a - * custom rendering. The $lid parameter is given if the user is editing - * (as opposed to adding) a node limit. The implementor should fill in a + * + * You may set the value '#custom_render' => true if your element requires a + * custom rendering. The $lid parameter is given if the user is editing + * (as opposed to adding) a node limit. The implementor should fill in a * #default_value for the element. - * + * * @param int $lid * The node limit id. + * * @return array - * An array with a single key-value pair. The key must be the name of the + * An array with a single key-value pair. The key must be the name of the * submodule, and the value is an element in form api. */ function hook_node_limit_element($lid = 0) { @@ -81,30 +84,31 @@ function hook_node_limit_element($lid = 0) { /** * Validate a submodules' elements values. - * - * Called when the user attempts to add or edit a Node Limit. The implementor + * + * Called when the user attempts to add or edit a Node Limit. The implementor * of the hook has the opportunity to validate the value the user entered. - * + * * @param object $element * The element. + * * @return array * TODO explain */ function hook_node_limit_element_validate($element) { - /** + /* * Validation: * User cannot be user:1 - * User must be in the {user} table + * User must be in the {user} table. */ $potential_user = user_load_by_name($element); if ($potential_user->uid == 1) { - //we cannot apply a limit to user:1 + // We cannot apply a limit to user:1. return array( 'error' => t('Node Limits cannot be applied to User #1') ); } elseif ($potential_user === FALSE) { - //unknown user + // Unknown user. return array( 'error' => t('Unknown user "!user"', array('!user' => $element)) ); @@ -114,13 +118,14 @@ function hook_node_limit_element_validate($element) { /** * Load submodules' data. - * + * * Called when node_limit loads a limit from the database. - * + * * @param int $lid * The node limit id. + * * @return array - * An array with a single key-value pair. The key must be the name of the + * An array with a single key-value pair. The key must be the name of the * submodule, and the value is an array containing submodule's data. */ function hook_node_limit_load($lid) { @@ -144,12 +149,13 @@ function hook_node_limit_load($lid) { /** * Special render for special elements. - * - * Called if the element returned from hook_node_limit_element has + * + * Called if the element returned from hook_node_limit_element has * '#custom_render' => true. - * + * * @param object $element * The element. + * * @return string * Rendered HTML. */ @@ -160,20 +166,20 @@ function hook_node_limit_render_element(&$element) { /** * Save submodules' data. - * + * * Called when saving a node limit for each submodule individually. - * + * * @param int $lid - * The node limit id + * The node limit id. * @param bool $applies - * TRUE if this submodule have been chosen + * TRUE if this submodule have been chosen. * @param mixed $element - * The form element value + * The form element value. */ function hook_node_limit_save($lid, $applies, $element) { if ($applies) { // $element contains the username of the user - // user_load based on the name to get the uid + // user_load based on the name to get the uid. $user = user_load_by_name($element); db_insert('submodule') @@ -187,17 +193,19 @@ function hook_node_limit_save($lid, $applies, $element) { /** * Improve node limit count request. - * + * * Called when counting nodes to know if a limit has been reached. - * + * * @param int $lid - * The node limit id + * The node limit id. * @param SelectQuery $select - * The SQL select query + * The SQL select query. */ -function hook_node_limit_sql($lid, $select) { +function hook_node_limit_sql($lid, SelectQuery $select) { $limit = submodule_node_limit_load($lid); - if (empty($limit)) return; - + if (empty($limit)) { + return; + } + $select->condition('uid', $limit['submodule']['uid']); -} \ No newline at end of file +} diff --git a/old/node_limit.install b/old/node_limit.install index ce01853..ab6a4d1 100644 --- a/old/node_limit.install +++ b/old/node_limit.install @@ -5,7 +5,9 @@ * Installation functions for module node_limit. */ -if (!defined("NODE_LIMIT_NO_LIMIT")) define("NODE_LIMIT_NO_LIMIT", -1); +if (!defined("NODE_LIMIT_NO_LIMIT")) { + define("NODE_LIMIT_NO_LIMIT", -1); +} /** * Implements hook_schema(). @@ -53,20 +55,22 @@ function node_limit_schema() { /** * Implements hook_update_N(). + * * Renaming limit field to avoid mysql restricted name usage. */ function node_limit_update_7001() { - // Cannot use db_change_field() because of the restricted name + // Cannot use db_change_field() because of the restricted name. $ret = db_query("ALTER TABLE {node_limit} CHANGE `limit` `limit_count` INT(11) NOT NULL DEFAULT '-1' COMMENT 'The node limit for this limit'"); return !empty($ret); } /** * Implements hook_update_N(). + * * Renaming limit_count field to keep names consistency. */ function node_limit_update_7002() { - $ret = db_change_field('node_limit', 'limit_count', 'nlimit', + $ret = db_change_field('node_limit', 'limit_count', 'nlimit', array( 'description' => 'The node limit for this limit', 'type' => 'int', diff --git a/old/node_limit.module b/old/node_limit.module index 4291c92..2f58892 100644 --- a/old/node_limit.module +++ b/old/node_limit.module @@ -5,7 +5,9 @@ * Module to restrict the number of nodes a user or role may create. */ -if (!defined("NODE_LIMIT_NO_LIMIT")) define("NODE_LIMIT_NO_LIMIT", -1); +if (!defined("NODE_LIMIT_NO_LIMIT")) { + define("NODE_LIMIT_NO_LIMIT", -1); +} define("NODE_LIMIT_PERM_ADMIN", "administer node limits"); define("NODE_LIMIT_PERM_OVERRIDE", "override node limits"); @@ -99,7 +101,7 @@ function node_limit_menu_alter(&$items) { node_type_cache_reset(); foreach (node_type_get_types() as $type) { $type_url_str = str_replace('_', '-', $type->type); - // Saving old access callbacks to allow other modules to define their own + // Saving old access callbacks to allow other modules to define their own. variable_set('node_limit_' . $type->type . '_access_callback', $items['node/add/' . $type_url_str]['access callback']); variable_set('node_limit_' . $type->type . '_access_arguments', $items['node/add/' . $type_url_str]['access arguments']); $items['node/add/' . $type_url_str]['access callback'] = 'node_limit_access'; @@ -110,6 +112,7 @@ function node_limit_menu_alter(&$items) { /** * Rewriten access callback for node/add page. + * * Avoid access to this page when the user does not have the right to add any content type. */ function _node_limit_add_access() { @@ -130,15 +133,16 @@ function _node_limit_add_access() { /** * Custom access callback for node/add/TYPE pages. - * @param $type - * Content type to check - * @param $account - * User account to check (default to current user) + * + * @param string $type + * Content type to check. + * @param object $account + * User account to check (default to current user). */ function node_limit_access($type, $account = NULL) { global $user; - if (empty($account)) { - $account = $user; + if (empty($account)) { + $account = $user; } $access = &drupal_static(__FUNCTION__, array()); @@ -151,10 +155,10 @@ function node_limit_access($type, $account = NULL) { $node->uid = $account->uid; $node->type = $type; - $oldCallback = variable_get('node_limit_' . $type . '_access_callback'); + $oldCallback = variable_get('node_limit_' . $type . '_access_callback'); $oldArguments = variable_get('node_limit_' . $type . '_access_arguments', array()); $oldAccess = function_exists($oldCallback) ? call_user_func_array($oldCallback, $oldArguments) : TRUE; - + $access[$account->uid][$type] = !_node_limit_violates_limit($node) && $oldAccess; } @@ -163,13 +167,11 @@ function node_limit_access($type, $account = NULL) { /** * Implements hook_theme(). + * * Register the two forms that require custom rendering. */ function node_limit_theme() { return array( -// 'node_limit_limit_form' => array( -// 'render element' => 'form', -// ), 'node_limit_list_limits' => array( 'render element' => 'form', ) @@ -181,16 +183,16 @@ function node_limit_theme() { * * This is where we'll determine if the user may create new nodes or not. * We'll use hook_node_prepare, which is sent before the edit/add form - * is constructed. + * is constructed. */ function node_limit_node_prepare($node) { if (empty($node->nid) && _node_limit_violates_limit($node)) { - //we have a violation! - //and this is a new node + // We have a violation + // and this is a new node. $nodetype = node_type_get_type($node); drupal_set_message(t("You can't create more content of type !type", array('!type' => check_plain($nodetype->name))), 'error'); - - // Avoid redirection loop if there is just one content type + + // Avoid redirection loop if there is just one content type. $count = 0; foreach (node_type_get_types() as $type) { if (node_limit_access($type->name)) { @@ -198,10 +200,10 @@ function node_limit_node_prepare($node) { } } if ($count > 1) { - drupal_goto('node/add'); - } + drupal_goto('node/add'); + } else { - drupal_goto(''); + drupal_goto(''); } } } @@ -211,8 +213,8 @@ function node_limit_node_prepare($node) { */ function node_limit_node_validate($node, $form, &$form_state) { if (empty($node->nid) && _node_limit_violates_limit($node)) { - //we have a violation! - //and this is a new node + // We have a violation + // and this is a new node. $nodetype = node_type_get_type($node); form_set_error('title', t("You can't create more content of type !type", array('!type' => check_plain($nodetype->name))), 'error'); } @@ -220,9 +222,10 @@ function node_limit_node_validate($node, $form, &$form_state) { /** * Helper function to check limit violations for this node. + * * Always returns FALSE for user 1. * - * @param $node + * @param object $node * The node to check. */ function _node_limit_violates_limit(&$node) { @@ -246,12 +249,13 @@ function _node_limit_violates_limit(&$node) { /** * Generates the sql statement to find the nodes that apply to a particular limit. + * * Modules that implement hook_node_limit_sql() should sprintf their arguments * into the returned array. * This will be changed in Drupal 7, which will be able to accept an array of * arguments to db_query(). * - * @param $lid + * @param int $lid * Identifier of limit rule. */ function _node_limit_sql($lid) { @@ -266,22 +270,22 @@ function _node_limit_sql($lid) { /** * Returns all the limits that can be applied to a specific node. * - * @param $node + * @param object $node * The node object that may be limited. */ function node_limit_limits(&$node) { $user = user_load($node->uid); - //get all the limits: + // Get all the limits. $query = db_select('node_limit', 'nl') ->fields('nl') ->orderBy('weight', 'ASC') ->execute(); - + $applicable_limits = array(); foreach ($query as $row) { // This particular limit id. $lid = $row->lid; - $applies = TRUE; + $applies = TRUE; $submodule_applies = module_invoke_all('node_limit_applies_in_context', $lid, $node, $user); foreach ($submodule_applies as $module => $module_applies) { @@ -332,11 +336,17 @@ function theme_node_limit_list_limits($variables) { drupal_add_tabledrag('node_limit', 'order', 'sibling', 'node_limit-weight'); } $header[] = array('data' => t('Actions'), 'colspan' => '3'); - return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No limit available.') . ' ' . drupal_render($form['create']), 'attributes' => array('id' => 'node_limit'))) . drupal_render_children($form); + return theme('table', array( + 'header' => $header, + 'rows' => $rows, + 'empty' => t('No limit available.') . ' ' . drupal_render($form['create']), + 'attributes' => array('id' => 'node_limit'), + )) . drupal_render_children($form); } /** * Form for listing the created limits. + * * Created as a form so that the user can adjust the weight. */ function node_limit_list_limits() { @@ -365,9 +375,21 @@ function node_limit_list_limits() { $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'); + $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) { @@ -378,9 +400,9 @@ function node_limit_list_limits() { } else { $form['create'] = array( - '#type' => 'link', - '#title' => t('Add a new node limit'), - '#href' => 'admin/structure/node_limit/add' + '#type' => 'link', + '#title' => t('Add a new node limit'), + '#href' => 'admin/structure/node_limit/add', ); } @@ -403,47 +425,8 @@ function node_limit_list_limits_submit($form_id, &$form_state) { } /** - * Theme the admin settings form so that we have tables inside fieldsets. - */ -/* -function theme_node_limit_limit_form($variables) { - $form = $variables['form']; -var_dump($form); - if (!isset($form['info'])) { - return; - } - $rows = array(); - - if (!empty($form['node_limit_elements'])) { - foreach ($form['node_limit_elements'] as $module => &$element) { - if (is_array($element['applies']) && is_array($element['element'])) { - if ($element['element']['#custom_render'] === TRUE && module_hook($module, 'node_limit_render_element')) { - // We can't use module_invoke because form elements must be passed byref. - $func = $module . '_node_limit_render_element'; - $rendered_element = $func($element['element']); - } - else { - $rendered_element = drupal_render($element['element']); - } - $rows[] = array( - drupal_render($element['applies']), - $rendered_element - ); - } - } - } - - $output = drupal_render($form['info']); - if (count($rows) > 0) { - $output .= theme('table', array(t('Applies to:'), ''), $rows); - } - $output .= drupal_render($form); - return $output; -} -// */ - -/** * Implements hook_form(). + * * The node_limit settings form. */ function node_limit_limit_form($form, &$form_state, $limit = FALSE) { @@ -453,7 +436,7 @@ function node_limit_limit_form($form, &$form_state, $limit = FALSE) { 'title' => '', 'weight' => 0, 'nlimit' => NODE_LIMIT_NO_LIMIT, - ); + ); } $form = array(); @@ -496,7 +479,9 @@ function node_limit_limit_form($form, &$form_state, $limit = FALSE) { $element['#title'] = ''; $form['node_limit_elements'][$module]['element'] = $element; } - if (empty($form['node_limit_elements'])) unset($form['node_limit_elements']); + if (empty($form['node_limit_elements'])) { + unset($form['node_limit_elements']); + } $form['save'] = array( '#type' => 'submit', @@ -568,7 +553,7 @@ function node_limit_limit_form_submit($form_id, &$form_state) { } } } - + node_limit_save($limit); $form_state['redirect'] = 'admin/structure/node_limit'; @@ -577,6 +562,7 @@ function node_limit_limit_form_submit($form_id, &$form_state) { /** * Implements hook_form(). + * * Confirmation form to delete a node limit. */ function node_limit_delete_form($form, &$form_state, $limit) { @@ -628,9 +614,10 @@ function _node_limit_next_limit_id() { /** * Loads a node limit. * - * @param $lid + * @param int $lid * The limit id. - * @return + * + * @return array|false * FALSE if the limit couldn't be loaded; otherwise the limit rule. */ function node_limit_load($lid) { @@ -643,9 +630,9 @@ function node_limit_load($lid) { ->execute() ->fetchAssoc(); if ($info['lid'] == $lid && intval($lid) >= 0) { - //load up the information from the other modules - //perhaps this isn't necessary. does node_limit ever use the other modules info? - //yes (for setting the default state of the "applies" checkbox when editing a limit) + // Load up the information from the other modules + // perhaps this isn't necessary. does node_limit ever use the other modules info? + // yes (for setting the default state of the "applies" checkbox when editing a limit). $res = module_invoke_all('node_limit_load', $lid); return array_merge($info, $res); } @@ -655,11 +642,11 @@ function node_limit_load($lid) { } /** - * Delete node limits - * - * @param $lid + * Delete node limits. + * + * @param array|int $lids * The limit id. - * @param $silent + * @param bool $silent * Hide success message. */ function node_limit_delete($lids, $silent = FALSE) { @@ -674,19 +661,21 @@ function node_limit_delete($lids, $silent = FALSE) { ->execute(); module_invoke_all('node_limit_delete', $lids); - + if ($num > 0 && !$silent) { - drupal_set_message(t('Deleted !num.', array('!num' => format_plural((int) $num, '1 limit rule', '@count limit rules')))); + drupal_set_message(t('Deleted !num.', array( + '!num' => format_plural((int) $num, '1 limit rule', '@count limit rules'), + ))); } } /** * Callback to save a node limit back to the database. - * - * @param $limit + * + * @param array $limit * The limit data. */ -function node_limit_save($limit) { +function node_limit_save(array $limit) { node_limit_delete($limit['lid'], TRUE); db_insert('node_limit') diff --git a/old/node_limit_interval/node_limit_interval.install b/old/node_limit_interval/node_limit_interval.install index f190928..821160c 100644 --- a/old/node_limit_interval/node_limit_interval.install +++ b/old/node_limit_interval/node_limit_interval.install @@ -35,19 +35,19 @@ function node_limit_interval_schema() { } /** - * Renaming interval field to avoid mysql restricted name usage + * Renaming interval field to avoid mysql restricted name usage. */ function node_limit_interval_update_7001() { - // Cannot use db_change_field() because of the restricted name + // Cannot use db_change_field() because of the restricted name. $ret = db_query("ALTER TABLE {node_limit_interval} CHANGE `interval` `interval_value` INT(11) NOT NULL DEFAULT '0' COMMENT 'The interval for this limit'"); return !empty($ret); } /** - * Renaming interval field to avoid mysql restricted name usage + * Renaming interval field to avoid mysql restricted name usage. */ function node_limit_interval_update_7002() { - $ret = db_change_field('node_limit_interval', 'interval_value', 'ninterval', + $ret = db_change_field('node_limit_interval', 'interval_value', 'ninterval', array( 'description' => 'The interval for this limit', 'type' => 'int', diff --git a/old/node_limit_interval/node_limit_interval.module b/old/node_limit_interval/node_limit_interval.module index e38ee09..5e58148 100644 --- a/old/node_limit_interval/node_limit_interval.module +++ b/old/node_limit_interval/node_limit_interval.module @@ -5,13 +5,13 @@ * Module to restrict the number of nodes within a time interval. */ - define("NODE_LIMIT_INTERVAL_SECONDS", "1"); - define("NODE_LIMIT_INTERVAL_MINUTES", "60"); - define("NODE_LIMIT_INTERVAL_HOURS", "3600"); - define("NODE_LIMIT_INTERVAL_DAYS", "86400"); - define("NODE_LIMIT_INTERVAL_WEEKS", "604800"); - define("NODE_LIMIT_INTERVAL_MONTHS", "2419200"); - define("NODE_LIMIT_INTERVAL_YEARS", "31536000"); +define("NODE_LIMIT_INTERVAL_SECONDS", "1"); +define("NODE_LIMIT_INTERVAL_MINUTES", "60"); +define("NODE_LIMIT_INTERVAL_HOURS", "3600"); +define("NODE_LIMIT_INTERVAL_DAYS", "86400"); +define("NODE_LIMIT_INTERVAL_WEEKS", "604800"); +define("NODE_LIMIT_INTERVAL_MONTHS", "2419200"); +define("NODE_LIMIT_INTERVAL_YEARS", "31536000"); /** * Implements hook_node_limit_applies_in_context(). @@ -30,14 +30,16 @@ function node_limit_interval_node_limit_applies_in_context($lid, $node, $user) { */ function node_limit_interval_node_limit_sql($lid, SelectQuery $select) { $limit = node_limit_interval_node_limit_load($lid); - if (empty($limit)) return; - + if (empty($limit)) { + return; + } + if ($limit['node_limit_interval'] != NODE_LIMIT_INTERVAL_MONTHS) { $interval = floatval($limit['node_limit_interval']['interval']) * - intval($limit['node_limit_interval']['unit']); + intval($limit['node_limit_interval']['unit']); } else { - $then = mktime(date('H'), date('i'), date('s'), date('n')-floatval($limit['node_limit_interval']['interval'])); + $then = mktime(date('H'), date('i'), date('s'), date('n') - floatval($limit['node_limit_interval']['interval'])); $now = mktime(); $interval = $now - $then; } @@ -62,7 +64,7 @@ function node_limit_interval_node_limit_render_element(&$element) { function node_limit_interval_node_limit_element($lid = 0) { $limit = node_limit_interval_node_limit_load($lid); $interval_options = _node_limit_interval_interval_options(); - + $interval = !empty($limit['node_limit_interval']['interval']) ? $limit['node_limit_interval']['interval'] : ''; $unit = !empty($limit['node_limit_interval']['unit']) ? $limit['node_limit_interval']['unit'] : ''; return array( @@ -103,16 +105,16 @@ function _node_limit_interval_interval_options() { * Implements hook_node_limit_element_validate(). */ function node_limit_interval_node_limit_element_validate($element) { - /** + /* * Validation: * interval must be an integer greater than 0 - * User must be in the {user} table + * User must be in the {user} table. */ if (!is_numeric($element['interval']) || floatval($element['interval']) <= 0) { - //less than 0 + // Less than 0. return array( 'error' => t('Time intervals must be an integer greater than 0'), - 'element' => 'interval' + 'element' => 'interval', ); } return TRUE; @@ -151,7 +153,7 @@ function node_limit_interval_node_limit_load($lid) { $select = db_select('node_limit_interval', 'nti') ->fields('nti') ->condition('lid', $lid); - + $info = $select->execute()->fetchAssoc(); if (empty($info['lid'])) { return array(); diff --git a/old/node_limit_role/node_limit_role.install b/old/node_limit_role/node_limit_role.install index de73935..1801132 100644 --- a/old/node_limit_role/node_limit_role.install +++ b/old/node_limit_role/node_limit_role.install @@ -24,10 +24,10 @@ function node_limit_role_schema() { 'unsigned' => TRUE, ) ), - //the limit-user combination is unique - /** + // The limit-user combination is unique. + /* * this means that in the future, we may allow a limit to be applied to more - * than one user. right now, though, its one-user-per-limit + * than one user. right now, though, its one-user-per-limit. */ 'primary key' => array('lid', 'rid') ); diff --git a/old/node_limit_role/node_limit_role.module b/old/node_limit_role/node_limit_role.module index cdb1cf3..7541047 100644 --- a/old/node_limit_role/node_limit_role.module +++ b/old/node_limit_role/node_limit_role.module @@ -46,14 +46,16 @@ function node_limit_role_node_limit_applies_in_context($lid, $node, $user) { */ function node_limit_role_node_limit_sql($lid, SelectQuery $select) { $limit = node_limit_role_node_limit_load($lid); - if (empty($limit)) return; - + if (empty($limit)) { + return; + } + if ($limit['node_limit_role']['rid'] == DRUPAL_ANONYMOUS_RID) { $select->condition('uid', 0); - } + } elseif ($limit['node_limit_role']['rid'] == DRUPAL_AUTHENTICATED_RID) { $select->condition('uid', 0, '!='); - } + } else { $subselect = db_select('users_roles', 'ur') ->fields('ur', array('uid')) @@ -68,9 +70,9 @@ function node_limit_role_node_limit_sql($lid, SelectQuery $select) { function node_limit_role_node_limit_element($lid = 0) { $limit = node_limit_role_node_limit_load($lid); $rid = !empty($limit['node_limit_role']['rid']) ? $limit['node_limit_role']['rid'] : ''; - + $roles = user_roles(); - + if (!empty($roles)) { return array( 'node_limit_role' => array( @@ -87,9 +89,9 @@ function node_limit_role_node_limit_element($lid = 0) { * Implements hook_node_limit_element_validate(). */ function node_limit_role_node_limit_element_validate($element) { - /** + /* * Validation: - * rid must be a role + * rid must be a role. */ $roles = user_roles(); if (!isset($roles[$element])) { @@ -106,8 +108,8 @@ function node_limit_role_node_limit_element_validate($element) { */ function node_limit_role_node_limit_save($lid, $applies, $element) { if ($applies) { - // In the clone context, $element is an array containing - // the rid and the role name + // In the clone context, $element is an array containing + // the rid and the role name. if (is_array($element)) { $element = $element['rid']; } diff --git a/old/node_limit_type/node_limit_type.install b/old/node_limit_type/node_limit_type.install index 7d772de..03c6edb 100644 --- a/old/node_limit_type/node_limit_type.install +++ b/old/node_limit_type/node_limit_type.install @@ -25,10 +25,10 @@ function node_limit_type_schema() { 'default' => '' ) ), - //the limit-type combination is unique - /** + // The limit-type combination is unique. + /* * this means that in the future, we may allow a limit to be applied to more - * than one type. right now, though, its one-type-per-limit + * than one type. right now, though, its one-type-per-limit. */ 'primary key' => array('lid', 'type') ); diff --git a/old/node_limit_type/node_limit_type.module b/old/node_limit_type/node_limit_type.module index 9aa4962..00715be 100644 --- a/old/node_limit_type/node_limit_type.module +++ b/old/node_limit_type/node_limit_type.module @@ -42,8 +42,10 @@ function node_limit_type_node_limit_applies_in_context($lid, $node, $user) { */ function node_limit_type_node_limit_sql($lid, SelectQuery $select) { $limit = node_limit_type_node_limit_load($lid); - if (empty($limit)) return; - + if (empty($limit)) { + return; + } + $select->condition('type', $limit['node_limit_type']); } diff --git a/old/node_limit_user/node_limit_user.install b/old/node_limit_user/node_limit_user.install index 56b40bb..4aaff6a 100644 --- a/old/node_limit_user/node_limit_user.install +++ b/old/node_limit_user/node_limit_user.install @@ -24,10 +24,10 @@ function node_limit_user_schema() { 'unsigned' => TRUE, ), ), - //the limit-user combination is unique - /** + // The limit-user combination is unique. + /* * this means that in the future, we may allow a limit to be applied to more - * than one user. right now, though, its one-user-per-limit + * than one user. right now, though, its one-user-per-limit. */ 'primary key' => array('lid', 'uid') ); diff --git a/old/node_limit_user/node_limit_user.module b/old/node_limit_user/node_limit_user.module index 38f6690..f25eccd 100644 --- a/old/node_limit_user/node_limit_user.module +++ b/old/node_limit_user/node_limit_user.module @@ -42,8 +42,10 @@ function node_limit_user_node_limit_applies_in_context($lid, $node, $user) { */ function node_limit_user_node_limit_sql($lid, SelectQuery $select) { $limit = node_limit_user_node_limit_load($lid); - if (empty($limit)) return; - + if (empty($limit)) { + return; + } + $select->condition('uid', $limit['node_limit_user']['uid']); } @@ -67,20 +69,20 @@ function node_limit_user_node_limit_element($lid = 0) { * Implements hook_node_limit_element_validate(). */ function node_limit_user_node_limit_element_validate($element) { - /** + /* * Validation: * User cannot be user:1 - * User must be in the {user} table + * User must be in the {user} table. */ $potential_user = user_load_by_name($element); if ($potential_user->uid == 1) { - //we cannot apply a limit to user:1 + // We cannot apply a limit to user:1. return array( 'error' => t('Node Limits cannot be applied to User #1') ); } elseif ($potential_user === FALSE) { - //unknown user + // Unknown user. return array( 'error' => t('Unknown user "!user"', array('!user' => $element)) ); @@ -93,14 +95,14 @@ function node_limit_user_node_limit_element_validate($element) { */ function node_limit_user_node_limit_save($lid, $applies, $element) { if ($applies) { - // In the clone context, $element is an array containing - // the uid and the user name + // In the clone context, $element is an array containing + // the uid and the user name. if (is_array($element)) { $uid = $element['uid']; } // In the creation/edition context // $element contains the username of the user - // user_load based on the name to get the uid + // user_load based on the name to get the uid. else { $user = user_load_by_name($element); $uid = $user->uid; diff --git a/old/node_limit_userofrole/node_limit_userofrole.install b/old/node_limit_userofrole/node_limit_userofrole.install index 7100dba..74aea98 100644 --- a/old/node_limit_userofrole/node_limit_userofrole.install +++ b/old/node_limit_userofrole/node_limit_userofrole.install @@ -24,10 +24,10 @@ function node_limit_userofrole_schema() { 'unsigned' => TRUE, ) ), - //the limit-user combination is unique - /** + // The limit-user combination is unique. + /* * this means that in the future, we may allow a limit to be applied to more - * than one user. right now, though, its one-user-per-limit + * than one user. right now, though, its one-user-per-limit. */ 'primary key' => array('lid', 'rid') ); diff --git a/old/node_limit_userofrole/node_limit_userofrole.module b/old/node_limit_userofrole/node_limit_userofrole.module index 870ea94..826a5f7 100644 --- a/old/node_limit_userofrole/node_limit_userofrole.module +++ b/old/node_limit_userofrole/node_limit_userofrole.module @@ -46,10 +46,12 @@ function node_limit_userofrole_node_limit_applies_in_context($lid, $node, $user) */ function node_limit_userofrole_node_limit_sql($lid, SelectQuery $select) { global $user; - + $limit = node_limit_userofrole_node_limit_load($lid); - if (empty($limit)) return; - + if (empty($limit)) { + return; + } + $select->condition('uid', $user->uid); } @@ -59,9 +61,9 @@ function node_limit_userofrole_node_limit_sql($lid, SelectQuery $select) { function node_limit_userofrole_node_limit_element($lid = 0) { $limit = node_limit_userofrole_node_limit_load($lid); $rid = !empty($limit['node_limit_userofrole']['rid']) ? $limit['node_limit_userofrole']['rid'] : ''; - + $roles = user_roles(); - + if (!empty($roles)) { return array( 'node_limit_userofrole' => array( @@ -78,9 +80,9 @@ function node_limit_userofrole_node_limit_element($lid = 0) { * Implements hook_node_limit_element_validate(). */ function node_limit_userofrole_node_limit_element_validate($element) { - /** + /* * Validation: - * rid must be a role + * rid must be a role. */ $roles = user_roles(); if (!isset($roles[$element])) { @@ -97,8 +99,8 @@ function node_limit_userofrole_node_limit_element_validate($element) { */ function node_limit_userofrole_node_limit_save($lid, $applies, $element) { if ($applies) { - // In the clone context, $element is an array containing - // the rid and the role name + // In the clone context, $element is an array containing + // the rid and the role name. if (is_array($element)) { $element = $element['rid']; } diff --git a/src/Controller/NodeLimitListBuilder.php b/src/Controller/NodeLimitListBuilder.php index 8f9a4b3..ccc5a10 100644 --- a/src/Controller/NodeLimitListBuilder.php +++ b/src/Controller/NodeLimitListBuilder.php @@ -1,10 +1,5 @@ getLabel($entity); $row['id'] = $entity->id(); // You probably want a few more properties here... return $row + parent::buildRow($entity); } + } diff --git a/src/Entity/NodeLimit.php b/src/Entity/NodeLimit.php index 62638fb..21444ed 100644 --- a/src/Entity/NodeLimit.php +++ b/src/Entity/NodeLimit.php @@ -1,10 +1,5 @@ t('Delete'); } /** - * {@inheritdoc} - */ + * {@inheritdoc} + */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->entity->delete(); @@ -57,4 +48,5 @@ class NodeLimitDeleteForm extends EntityConfirmFormBase $form_state->setRedirectUrl($this->getCancelUrl()); } + } diff --git a/src/Form/NodeLimitForm.php b/src/Form/NodeLimitForm.php index 48eff5a..564a0bf 100644 --- a/src/Form/NodeLimitForm.php +++ b/src/Form/NodeLimitForm.php @@ -1,21 +1,15 @@ entity; $status = $node_limit->save(); @@ -66,4 +60,5 @@ class NodeLimitForm extends EntityForm } $form_state->setRedirect('entity.node_limit.list'); } + } diff --git a/src/NodeLimitInterface.php b/src/NodeLimitInterface.php index ff35640..cfdaf3e 100644 --- a/src/NodeLimitInterface.php +++ b/src/NodeLimitInterface.php @@ -1,10 +1,5 @@