• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP filter_get_roles_by_format函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中filter_get_roles_by_format函数的典型用法代码示例。如果您正苦于以下问题:PHP filter_get_roles_by_format函数的具体用法?PHP filter_get_roles_by_format怎么用?PHP filter_get_roles_by_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了filter_get_roles_by_format函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:60,代码来源:FilterFormatFormBase.php


示例2: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     if (!$this->entity->status()) {
         throw new NotFoundHttpException();
     }
     $form['#title'] = $this->entity->label();
     $form = parent::form($form, $form_state);
     $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity));
     return $form;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:FilterFormatEditForm.php


示例3: testUpdateRoles

 /**
  * Tests that changes to FilterFormat::$roles do not have an effect.
  */
 function testUpdateRoles()
 {
     // Verify role permissions declared in default config.
     $format = entity_load('filter_format', 'filter_test');
     $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID));
     // Attempt to change roles.
     $format->set('roles', array(DRUPAL_AUTHENTICATED_RID));
     $format->save();
     // Verify that roles have not been updated.
     $format = entity_load('filter_format', 'filter_test');
     $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID));
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:15,代码来源:FilterDefaultConfigTest.php


示例4: testUpdateRoles

 /**
  * Tests that changes to FilterFormat::$roles do not have an effect.
  */
 function testUpdateRoles()
 {
     // Verify role permissions declared in default config.
     $format = FilterFormat::load('filter_test');
     $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID));
     // Attempt to change roles.
     $format->set('roles', array(RoleInterface::AUTHENTICATED_ID));
     $format->save();
     // Verify that roles have not been updated.
     $format = FilterFormat::load('filter_test');
     $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:FilterDefaultConfigTest.php


示例5: testFormatRoles

 /**
  * Tests if text format is available to a role.
  */
 function testFormatRoles()
 {
     // Get the role ID assigned to the regular user.
     $roles = $this->webUser->getRoles(TRUE);
     $rid = $roles[0];
     // Check that this role appears in the list of roles that have access to an
     // allowed text format, but does not appear in the list of roles that have
     // access to a disallowed text format.
     $this->assertTrue(in_array($rid, array_keys(filter_get_roles_by_format($this->allowedFormat))), 'A role which has access to a text format appears in the list of roles that have access to that format.');
     $this->assertFalse(in_array($rid, array_keys(filter_get_roles_by_format($this->disallowedFormat))), 'A role which does not have access to a text format does not appear in the list of roles that have access to that format.');
     // Check that the correct text format appears in the list of formats
     // available to that role.
     $this->assertTrue(in_array($this->allowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
     $this->assertFalse(in_array($this->disallowedFormat->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');
     // Check that the fallback format is always allowed.
     $this->assertEqual(filter_get_roles_by_format(FilterFormat::load(filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
     $this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), 'The fallback format appears in the list of allowed formats for any role.');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:21,代码来源:FilterFormatAccessTest.php


示例6: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     // Check whether this is the fallback text format. This format is available
     // to all roles and cannot be disabled via the admin interface.
     if ($entity->isFallbackFormat()) {
         $row['label'] = SafeMarkup::placeholder($entity->label());
         $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
         if ($fallback_choice) {
             $roles_markup = SafeMarkup::placeholder($this->t('All roles may use this format'));
         } else {
             $roles_markup = SafeMarkup::placeholder($this->t('This format is shown when no other formats are available'));
         }
     } else {
         $row['label'] = $this->getLabel($entity);
         $roles = array_map('\\Drupal\\Component\\Utility\\SafeMarkup::checkPlain', filter_get_roles_by_format($entity));
         $roles_markup = $roles ? implode(', ', $roles) : $this->t('No roles may use this format');
     }
     $row['roles'] = !empty($this->weightKey) ? array('#markup' => $roles_markup) : $roles_markup;
     return $row + parent::buildRow($entity);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:23,代码来源:FilterFormatListBuilder.php


示例7: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     // Check whether this is the fallback text format. This format is available
     // to all roles and cannot be disabled via the admin interface.
     $row['label'] = $entity->label();
     $row['roles'] = [];
     if ($entity->isFallbackFormat()) {
         $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
         if ($fallback_choice) {
             $row['roles']['#markup'] = $this->t('All roles may use this format');
         } else {
             $row['roles']['#markup'] = $this->t('This format is shown when no other formats are available');
         }
         // Emphasize the fallback role text since it is important to understand
         // how it works which configuring filter formats. Additionally, it is not
         // a list of roles unlike the other values in this column.
         $row['roles']['#prefix'] = '<em>';
         $row['roles']['#suffix'] = '</em>';
     } else {
         $row['roles'] = ['#theme' => 'item_list', '#items' => filter_get_roles_by_format($entity), '#empty' => $this->t('No roles may use this format'), '#context' => ['list_style' => 'comma-list']];
     }
     return $row + parent::buildRow($entity);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:FilterFormatListBuilder.php


示例8: getFormatRoles

 /**
  * Retrieves a list of roles for a given text format.
  *
  * @param string $format_name
  *    Text format machine name.
  *
  * @return array
  *    An array of role names, keyed by role ID.
  */
 public function getFormatRoles($format_name)
 {
     $format = $this->getFormat($format_name);
     return filter_get_roles_by_format($format);
 }
开发者ID:ec-europa,项目名称:platform-dev,代码行数:14,代码来源:Config.php


示例9: checkPhpFilter

 /**
  * @return array
  */
 protected function checkPhpFilter()
 {
     $result = TRUE;
     $check_result_value = array();
     $formats = \Drupal::entityManager()->getStorage('filter_format')->loadByProperties(array('status' => TRUE));
     // Check formats that are accessible by untrusted users.
     $untrusted_roles = $this->untrustedRoles();
     $untrusted_roles = array_keys($untrusted_roles);
     foreach ($formats as $id => $format) {
         $format_roles = filter_get_roles_by_format($format);
         $intersect = array_intersect(array_keys($format_roles), $untrusted_roles);
         if (!empty($intersect)) {
             // Untrusted users can use this format.
             $filters = $formats[$id]->get('filters');
             // Check format for enabled PHP filter.
             if (in_array('php_code', array_keys($filters)) && $filters['php_code']['status'] == 1) {
                 $result = FALSE;
                 $check_result_value['formats'][$id] = $format;
             }
         }
     }
     return array('result' => $result, 'value' => $check_result_value);
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:26,代码来源:SecurityReviewController.php


示例10: getMediumId

 /**
  * Returns the selected Medium Editor id for an account from editor settings.
  */
 public static function getMediumId(Editor $editor, AccountInterface $account)
 {
     $settings = $editor->getSettings();
     if (!empty($settings['roles_editors'])) {
         // Filter roles in two steps. May avoid a db hit by filter_get_roles_by_format().
         if ($roles_editors = array_intersect_key($settings['roles_editors'], array_flip($account->getRoles()))) {
             if ($roles_editors = array_intersect_key($roles_editors, filter_get_roles_by_format($editor->getFilterFormat()))) {
                 return reset($roles_editors);
             }
         }
     }
     return $settings['default_editor'];
 }
开发者ID:digideskio,项目名称:medium-editor-d8,代码行数:16,代码来源:MediumEditor.php


示例11: buildRow

 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     // Check whether this is the fallback text format. This format is available
     // to all roles and cannot be disabled via the admin interface.
     $row['label'] = $this->getLabel($entity);
     $row['roles'] = [];
     if ($entity->isFallbackFormat()) {
         $fallback_choice = $this->configFactory->get('filter.settings')->get('always_show_fallback_choice');
         if ($fallback_choice) {
             $roles_markup = $this->t('All roles may use this format');
         } else {
             $roles_markup = $this->t('This format is shown when no other formats are available');
         }
         // Emphasize the fallback role text since it is important to understand
         // how it works which configuring filter formats. Additionally, it is not
         // a list of roles unlike the other values in this column.
         $row['roles']['#prefix'] = '<em>';
         $row['roles']['#suffix'] = '</em>';
     } else {
         $roles = array_map('\\Drupal\\Component\\Utility\\SafeMarkup::checkPlain', filter_get_roles_by_format($entity));
         $roles_markup = $roles ? implode(', ', $roles) : $this->t('No roles may use this format');
     }
     $row['roles']['#markup'] = $roles_markup;
     return $row + parent::buildRow($entity);
 }
开发者ID:scratch,项目名称:gai,代码行数:28,代码来源:FilterFormatListBuilder.php



注:本文中的filter_get_roles_by_format函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP filter_get_time_based_rule_status函数代码示例发布时间:2022-05-15
下一篇:
PHP filter_get_plugin_filters函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap