本文整理汇总了PHP中user_role_names函数的典型用法代码示例。如果您正苦于以下问题:PHP user_role_names函数的具体用法?PHP user_role_names怎么用?PHP user_role_names使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_role_names函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$sanitized_id = ArgumentPluginBase::encodeValidatorId($this->definition['id']);
$form['restrict_roles'] = array('#type' => 'checkbox', '#title' => $this->t('Restrict user based on role'), '#default_value' => $this->options['restrict_roles']);
$form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Restrict to the selected roles'), '#options' => array_map(array('\\Drupal\\Component\\Utility\\SafeMarkup', 'checkPlain'), user_role_names(TRUE)), '#default_value' => $this->options['roles'], '#description' => $this->t('If no roles are selected, users from any role will be allowed.'), '#states' => array('visible' => array(':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]' => array('checked' => TRUE))));
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$default_role_choices = user_role_names(TRUE);
unset($default_role_choices[DRUPAL_AUTHENTICATED_RID]);
$roles_config = $this->config('uc_role.settings');
if (!count($default_role_choices)) {
$form['no_roles'] = array('#markup' => $this->t('You need to <a href=":url">create new roles</a> before any can be added as product features.', [':url' => Url::fromRoute('user.role_add', [], ['query' => ['destination' => 'admin/store/config/products']])->toString()]), '#prefix' => '<p>', '#suffix' => '</p>');
return $form;
}
$form['default_role'] = array('#type' => 'select', '#title' => $this->t('Default role'), '#default_value' => $roles_config->get('default_role'), '#description' => $this->t('The default role Ubercart grants on specified products.'), '#options' => _uc_role_get_choices());
$form['default_role_choices'] = array('#type' => 'checkboxes', '#title' => $this->t('Product roles'), '#default_value' => $roles_config->get('default_role_choices'), '#multiple' => TRUE, '#description' => $this->t('These are roles that Ubercart can grant to customers who purchase specified products. If you leave all roles unchecked, they will all be eligible for adding to a product.'), '#options' => $default_role_choices);
$form['role_lifetime'] = array('#type' => 'fieldset', '#title' => $this->t('Default role expiration'));
$form['role_lifetime']['default_end_expiration'] = array('#type' => 'select', '#title' => $this->t('Expiration type'), '#options' => array('rel' => $this->t('Relative to purchase date'), 'abs' => $this->t('Fixed date')), '#default_value' => $roles_config->get('default_end_expiration'));
$form['role_lifetime']['default_length'] = array('#type' => 'textfield', '#default_value' => $roles_config->get('default_granularity') == 'never' ? NULL : $roles_config->get('default_length'), '#size' => 4, '#maxlength' => 4, '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'rel')), 'invisible' => array('select[name="default_granularity"]' => array('value' => 'never'))));
$form['role_lifetime']['default_granularity'] = array('#type' => 'select', '#default_value' => $roles_config->get('default_granularity'), '#options' => array('never' => $this->t('never'), 'day' => $this->t('day(s)'), 'week' => $this->t('week(s)'), 'month' => $this->t('month(s)'), 'year' => $this->t('year(s)')), '#description' => $this->t('From the time the role was purchased.'), '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'rel'))));
$form['role_lifetime']['absolute'] = array('#type' => 'container', '#states' => array('visible' => array('select[name="default_end_expiration"]' => array('value' => 'abs'))));
$date = (int) $roles_config->get('default_end_time');
$date = !empty($date) ? DrupalDateTime::createFromTimestamp($date) : DrupalDateTime::createFromTimestamp(REQUEST_TIME);
$form['role_lifetime']['absolute']['default_end_time'] = array('#type' => 'datetime', '#description' => $this->t('Expire the role at the beginning of this day.'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => $date);
$form['role_lifetime']['default_by_quantity'] = array('#type' => 'checkbox', '#title' => $this->t('Multiply by quantity'), '#description' => $this->t('Check if the role duration should be multiplied by the quantity purchased.'), '#default_value' => $roles_config->get('default_by_quantity'));
$form['reminder']['reminder_length'] = array('#type' => 'textfield', '#title' => $this->t('Time before reminder'), '#default_value' => $roles_config->get('reminder_granularity') == 'never' ? NULL : $roles_config->get('reminder_length'), '#size' => 4, '#maxlength' => 4, '#prefix' => '<div class="expiration">', '#suffix' => '</div>', '#states' => array('disabled' => array('select[name="reminder_granularity"]' => array('value' => 'never'))));
$form['reminder']['reminder_granularity'] = array('#type' => 'select', '#default_value' => $roles_config->get('reminder_granularity'), '#options' => array('never' => $this->t('never'), 'day' => $this->t('day(s)'), 'week' => $this->t('week(s)'), 'month' => $this->t('month(s)'), 'year' => $this->t('year(s)')), '#description' => $this->t('The amount of time before a role expiration takes place that a customer is notified of its expiration.'), '#prefix' => '<div class="expiration">', '#suffix' => '</div>');
$form['default_show_expiration'] = array('#type' => 'checkbox', '#title' => $this->t('Show expirations on user page'), '#default_value' => $roles_config->get('default_show_expiration'), '#description' => $this->t('If users have any role expirations they will be displayed on their account page.'));
return parent::buildForm($form, $form_state);
}
示例3: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, array &$form_state)
{
$roles = user_role_names(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
$form['rid'] = array('#type' => 'radios', '#title' => t('Role'), '#options' => $roles, '#default_value' => $this->configuration['rid'], '#required' => TRUE);
return $form;
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['to']['#markup'] = $this->stateStorage->load($entity->getToState())->label();
$row['label'] = $entity->label();
$row['roles']['#markup'] = implode(', ', user_role_names(FALSE, 'use ' . $entity->id() . ' transition'));
return $row + parent::buildRow($entity);
}
示例5: summary
/**
* {@inheritdoc}
*/
public function summary()
{
if (!$this->configuration['roles']) {
return $this->t('Any registered user');
}
$roles = array_intersect_key(user_role_names(), $this->configuration['roles']);
return $this->t(empty($this->configuration['negate']) ? 'User is a member of @roles' : 'User is not a member of @roles', ['@roles' => count($roles) > 1 ? implode(' and ', $roles) : reset($roles)]);
}
示例6: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$format = $this->entity;
$is_fallback = $format->id() == $this->config('filter.settings')->get('fallback_format');
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'filter/drupal.filter.admin';
$form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $format->label(), '#required' => TRUE, '#weight' => -30);
$form['format'] = array('#type' => 'machine_name', '#required' => TRUE, '#default_value' => $format->id(), '#maxlength' => 255, '#machine_name' => array('exists' => array($this, 'exists'), 'source' => array('name')), '#disabled' => !$format->isNew(), '#weight' => -20);
// Add user role access selection.
$form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Roles'), '#options' => array_map('\\Drupal\\Component\\Utility\\String::checkPlain', user_role_names()), '#disabled' => $is_fallback, '#weight' => -10);
if ($is_fallback) {
$form['roles']['#description'] = $this->t('All roles for this text format must be enabled and cannot be changed.');
}
if (!$format->isNew()) {
// If editing an existing text format, pre-select its current permissions.
$form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($format));
} elseif ($admin_role = $this->config('user.settings')->get('admin_role')) {
// If adding a new text format and the site has an administrative role,
// pre-select that role so as to grant administrators access to the new
// text format permission by default.
$form['roles']['#default_value'] = array($admin_role);
}
// Create filter plugin instances for all available filters, including both
// enabled/configured ones as well as new and not yet unconfigured ones.
$filters = $format->filters();
foreach ($filters as $filter_id => $filter) {
// When a filter is missing, it is replaced by the null filter. Remove it
// here, so that saving the form will remove the missing filter.
if ($filter instanceof FilterNull) {
drupal_set_message($this->t('The %filter filter is missing, and will be removed once this format is saved.', array('%filter' => $filter_id)), 'warning');
$filters->removeInstanceID($filter_id);
}
}
// Filter status.
$form['filters']['status'] = array('#type' => 'item', '#title' => $this->t('Enabled filters'), '#prefix' => '<div id="filters-status-wrapper">', '#suffix' => '</div>', '#input' => FALSE);
// Filter order (tabledrag).
$form['filters']['order'] = array('#type' => 'table', '#attributes' => array('id' => 'filter-order'), '#title' => $this->t('Filter processing order'), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'filter-order-weight')), '#tree' => FALSE, '#input' => FALSE, '#theme_wrappers' => array('form_element'));
// Filter settings.
$form['filter_settings'] = array('#type' => 'vertical_tabs', '#title' => $this->t('Filter settings'));
foreach ($filters as $name => $filter) {
$form['filters']['status'][$name] = array('#type' => 'checkbox', '#title' => $filter->getLabel(), '#default_value' => $filter->status, '#parents' => array('filters', $name, 'status'), '#description' => $filter->getDescription(), '#weight' => $filter->weight);
$form['filters']['order'][$name]['#attributes']['class'][] = 'draggable';
$form['filters']['order'][$name]['#weight'] = $filter->weight;
$form['filters']['order'][$name]['filter'] = array('#markup' => $filter->getLabel());
$form['filters']['order'][$name]['weight'] = array('#type' => 'weight', '#title' => $this->t('Weight for @title', array('@title' => $filter->getLabel())), '#title_display' => 'invisible', '#delta' => 50, '#default_value' => $filter->weight, '#parents' => array('filters', $name, 'weight'), '#attributes' => array('class' => array('filter-order-weight')));
// Retrieve the settings form of the filter plugin. The plugin should not be
// aware of the text format. Therefore, it only receives a set of minimal
// base properties to allow advanced implementations to work.
$settings_form = array('#parents' => array('filters', $name, 'settings'), '#tree' => TRUE);
$settings_form = $filter->settingsForm($settings_form, $form_state);
if (!empty($settings_form)) {
$form['filters']['settings'][$name] = array('#type' => 'details', '#title' => $filter->getLabel(), '#open' => TRUE, '#weight' => $filter->weight, '#parents' => array('filters', $name, 'settings'), '#group' => 'filter_settings');
$form['filters']['settings'][$name] += $settings_form;
}
}
return parent::form($form, $form_state);
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Get all available roles except for
// 'anonymous user' and 'authenticated user'.
$roles = user_role_names(TRUE);
unset($roles[RoleInterface::AUTHENTICATED_ID]);
// Show checkboxes with roles that can be delegated if any.
if ($roles) {
$config = $this->config('roleassign.settings');
$form['roleassign_roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Roles'), '#default_value' => $config->get('roleassign_roles'), '#options' => $roles, '#description' => $this->t('Select roles that should be available for assignment.'));
}
return parent::buildForm($form, $form_state);
}
示例8: createConditionElements
/**
*
*/
public function createConditionElements() {
$elements['condition_config'] = [
'#tree' => TRUE,
];
// @todo Dynamically create condition for by call ConditionPluginBase::buildConfigurationForm?
$elements['condition_config']['roles'] = array(
'#type' => 'checkboxes',
'#title' => $this->t('When the user has the following roles'),
'#options' => array_map('\Drupal\Component\Utility\Html::escape', user_role_names()),
// '#description' => $this->t('If you select no roles, the condition will evaluate to TRUE for all users.'),.
);
return $elements;
}
示例9: query
/**
* {@inheritdoc}
*
* Replace the configured permission with a filter by all roles that have this
* permission.
*/
public function query()
{
// @todo user_role_names() should maybe support multiple permissions.
$rids = array();
// Get all roles, that have the configured permissions.
foreach ($this->value as $permission) {
$roles = user_role_names(FALSE, $permission);
$rids += array_keys($roles);
}
$rids = array_unique($rids);
$this->value = $rids;
// $this->value contains the role IDs that have the configured permission.
parent::query();
}
示例10: summary
/**
* {@inheritdoc}
*/
public function summary()
{
// Use the role labels. They will be sanitized below.
$roles = array_intersect_key(user_role_names(), $this->configuration['roles']);
if (count($roles) > 1) {
$roles = implode(', ', $roles);
} else {
$roles = reset($roles);
}
if (!empty($this->configuration['negate'])) {
return $this->t('The user is not a member of @roles', array('@roles' => $roles));
} else {
return $this->t('The user is a member of @roles', array('@roles' => $roles));
}
}
示例11: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state)
{
$form['num'] = array('#type' => 'number', '#title' => $this->t('How many users would you like to generate?'), '#default_value' => $this->getSetting('num'), '#required' => TRUE, '#min' => 0);
$form['kill'] = array('#type' => 'checkbox', '#title' => $this->t('Delete all users (except user id 1) before generating new users.'), '#default_value' => $this->getSetting('kill'));
$options = user_role_names(TRUE);
unset($options[DRUPAL_AUTHENTICATED_RID]);
$form['roles'] = array('#type' => 'checkboxes', '#title' => $this->t('Which roles should the users receive?'), '#description' => $this->t('Users always receive the <em>authenticated user</em> role.'), '#options' => $options);
$form['pass'] = array('#type' => 'textfield', '#title' => $this->t('Password to be set'), '#default_value' => $this->getSetting('pass'), '#size' => 32, '#description' => $this->t('Leave this field empty if you do not need to set a password'));
$options = array(1 => $this->t('Now'));
foreach (array(3600, 86400, 604800, 2592000, 31536000) as $interval) {
$options[$interval] = $this->dateFormatter->formatInterval($interval, 1) . ' ' . $this->t('ago');
}
$form['time_range'] = array('#type' => 'select', '#title' => $this->t('How old should user accounts be?'), '#description' => $this->t('User ages will be distributed randomly from the current time, back to the selected time.'), '#options' => $options, '#default_value' => 604800);
return $form;
}
示例12: settingsForm
/**
* {@inheritdoc}
*/
public static function settingsForm(FieldDefinitionInterface $field_definition)
{
$selection_handler_settings = $field_definition->getSetting('handler_settings');
// Merge in default values.
$selection_handler_settings += array('filter' => array('type' => '_none'));
// Add user specific filter options.
$form['filter']['type'] = array('#type' => 'select', '#title' => t('Filter by'), '#options' => array('_none' => t('- None -'), 'role' => t('User role')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['filter']['type']);
$form['filter']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array('_entity_reference_form_process_merge_parent'));
if ($selection_handler_settings['filter']['type'] == 'role') {
// Merge in default values.
$selection_handler_settings['filter'] += array('role' => NULL);
$form['filter']['settings']['role'] = array('#type' => 'checkboxes', '#title' => t('Restrict to the selected roles'), '#required' => TRUE, '#options' => array_diff_key(user_role_names(TRUE), array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID)), '#default_value' => $selection_handler_settings['filter']['role']);
}
$form += parent::settingsForm($field_definition);
return $form;
}
示例13: buildForm
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*
* @param array $form
* The form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return array $form
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['#tree'] = TRUE;
$form['config'] = ['#type' => 'fieldset', '#title' => $this->t('Options')];
$roles = user_role_names();
unset($roles['anonymous']);
$form['config']['roles'] = ['#type' => 'checkboxes', '#title' => $this->t('Roles'), '#options' => $roles];
// Special handling for the inevitable "Authenticated user" role.
$form['config']['roles'][RoleInterface::AUTHENTICATED_ID] = array('#default_value' => TRUE, '#disabled' => TRUE);
$form['file'] = ['#type' => 'file', '#title' => 'CSV file upload', '#upload_validators' => ['file_validate_extensions' => ['csv']]];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Import users'), '#button_type' => 'primary');
// By default, render the form using theme_system_config_form().
$form['#theme'] = 'system_config_form';
return $form;
}
示例14: buildConfigurationForm
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state)
{
$selection_handler_settings = $this->configuration['handler_settings'];
// Merge in default values.
$selection_handler_settings += array('filter' => array('type' => '_none'), 'include_anonymous' => TRUE);
$form['include_anonymous'] = array('#type' => 'checkbox', '#title' => $this->t('Include the anonymous user.'), '#default_value' => $selection_handler_settings['include_anonymous']);
// Add user specific filter options.
$form['filter']['type'] = array('#type' => 'select', '#title' => $this->t('Filter by'), '#options' => array('_none' => $this->t('- None -'), 'role' => $this->t('User role')), '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['filter']['type']);
$form['filter']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array(array('\\Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\EntityReferenceItem', 'formProcessMergeParent')));
if ($selection_handler_settings['filter']['type'] == 'role') {
// Merge in default values.
$selection_handler_settings['filter'] += array('role' => NULL);
$form['filter']['settings']['role'] = array('#type' => 'checkboxes', '#title' => $this->t('Restrict to the selected roles'), '#required' => TRUE, '#options' => array_diff_key(user_role_names(TRUE), array(RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID)), '#default_value' => $selection_handler_settings['filter']['role']);
}
$form += parent::buildConfigurationForm($form, $form_state);
return $form;
}
示例15: query
/**
* {@inheritdoc}
*
* Replace the configured permission with a filter by all roles that have this
* permission.
*/
public function query()
{
// @todo user_role_names() should maybe support multiple permissions.
$rids = array();
// Get all role IDs that have the configured permissions.
foreach ($this->value as $permission) {
$roles = user_role_names(FALSE, $permission);
// user_role_names() returns an array with the role IDs as keys, so take
// the array keys and merge them with previously found role IDs.
$rids = array_merge($rids, array_keys($roles));
}
// Remove any duplicate role IDs.
$rids = array_unique($rids);
$this->value = $rids;
// $this->value contains the role IDs that have the configured permission.
parent::query();
}