Пример #1
0
 /**
  * Overrides Drupal\configuration\Config\Configuration::alterDependencies().
  */
 public static function alterDependencies(Configuration $config)
 {
     if ($config->getComponent() == 'content_type') {
         $permissions = node_list_permissions($config->getIdentifier());
         foreach (array_keys($permissions) as $permission) {
             $identifier = str_replace(' ', '_', $permission);
             $perm = new PermissionConfiguration($identifier);
             $perm->build();
             // Add the content type as a dependency of the permission.
             $perm->addToDependencies($config);
             // Add the permission as a child configuration of the content type
             // The permission is not required to load the content type but is
             // a nice to have.
             $config->addToOptionalConfigurations($perm);
         }
     } elseif ($config->getComponent() == 'text_format') {
         $format = $config->getData();
         $permission = filter_permission_name($format);
         if (!empty($permission)) {
             $identifier = str_replace(' ', '_', $permission);
             $perm = new PermissionConfiguration($identifier);
             $perm->build();
             // Add the text format as a dependency of the permission.
             $perm->addToDependencies($config);
             // Add the permission as a child configuration of the filter
             // The permission is not required to load the filter format but is
             // a nice to have.
             $config->addToOptionalConfigurations($perm);
         }
     }
 }
Пример #2
0
 /**
  * Setup the test enviroment
  */
 function setUp()
 {
     parent::setUp();
     // Create and log in an administrative user having access to the Full HTML
     // text format.
     $full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
     $adminuser = $this->drupalCreateUser(array('administer blocks', filter_permission_name($full_html_format), 'access administration pages', 'access dashboard'));
     $this->drupalLogin($adminuser);
     // Define the existing regions.
     $this->regions = array();
     $this->regions[] = array('name' => 'header', 'class' => 'region region-header clearfix');
     $this->regions[] = array('name' => 'sidebar_first');
     $this->regions[] = array('name' => 'content');
     $this->regions[] = array('name' => 'sidebar_second');
     $this->regions[] = array('name' => 'footer');
 }
Пример #3
0
 /**
  * Overrides Drupal\configuration\Config\Configuration::alterDependencies().
  */
 public static function alterDependencies(Configuration $config)
 {
     if ($config->getComponent() == 'permission') {
         // Generate permissions for each text format. Warn the administrator that any
         // of them are potentially unsafe.
         foreach (filter_formats() as $format) {
             $permission = filter_permission_name($format);
             if (!empty($permission)) {
                 $data = $config->getData();
                 if ($permission == $data['permission']) {
                     $text_format = ConfigurationManagement::createConfigurationInstance('text_format.' . $format->format);
                     $config->addToDependencies($text_format);
                     break;
                 }
             }
         }
     }
 }
Пример #4
0
 /**
  * Makes sure that the PHP filter evaluates PHP code when used.
  */
 function testPhpFilter()
 {
     // Log in as a user with permission to use the PHP code text format.
     $php_code_permission = filter_permission_name(filter_format_load('php_code'));
     $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission));
     $this->drupalLogin($web_user);
     // Create a node with PHP code in it.
     $node = $this->createNodeWithCode();
     // Make sure that the PHP code shows up as text.
     $this->drupalGet('node/' . $node->nid);
     $this->assertText('php print');
     // Change filter to PHP filter and see that PHP code is evaluated.
     $edit = array();
     $langcode = LANGUAGE_NOT_SPECIFIED;
     $edit["body[{$langcode}][0][format]"] = $this->php_code_format->format;
     $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
     $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->label())), 'PHP code filter turned on.');
     // Make sure that the PHP code shows up as text.
     $this->assertNoText('print "SimpleTest PHP was executed!"', "PHP code isn't displayed.");
     $this->assertText('SimpleTest PHP was executed!', 'PHP code has been evaluated.');
 }
Пример #5
0
 /**
  * Set roles for the specified text format.
  *
  * @param string $format_name
  *    Text format machine name.
  * @param array $roles
  *    Roles array keyed by the role ID.
  *
  * @return bool
  *    TRUE / FALSE when filter name is invalid.
  */
 public function setFormatRoles($format_name, $roles)
 {
     $format = $this->getFormat($format_name);
     // Save user permissions.
     if ($permission = filter_permission_name($format)) {
         foreach ($roles as $rid => $enabled) {
             user_role_change_permissions($rid, array($permission => $enabled));
         }
         return TRUE;
     }
     return FALSE;
 }