Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm()
 {
     global $user;
     $output = array();
     // Show which users can access this node.
     $menu_item = menu_get_item();
     $map = $menu_item['original_map'];
     if ($map[0] != 'node' || !isset($map[1]) || !is_numeric($map[1]) || isset($map[2])) {
         // Ignore anything but node/%.
         return NULL;
     }
     if (isset($menu_item['map'][1]) && is_object($node = $menu_item['map'][1])) {
         // We have the node.
     } elseif (is_numeric($menu_item['original_map'][1])) {
         $node = node_load($menu_item['original_map'][1]);
     }
     if (isset($node)) {
         $nid = $node->id();
         $langcode = $node->langcode->value;
         $language = language_load($langcode);
         $node_type = node_type_load($node->bundle());
         $headers = array(t('username'), '<span title="' . t("Create '@langname'-language nodes of the '@Node_type' type.", array('@langname' => $language->name, '@Node_type' => $node_type->name)) . '">' . t('create') . '</span>', t('view'), t('update'), t('delete'));
         $rows = array();
         // Determine whether to use Ajax or pre-populate the tables.
         if ($ajax = \Drupal::config('devel_node_access.settings')->get('user_ajax')) {
             $output['#attached']['library'][] = 'devel_node_access/node_access';
         }
         // Find all users. The following operations are very inefficient, so we
         // limit the number of users returned.  It would be better to make a
         // pager query, or at least make the number of users configurable.  If
         // anyone is up for that please submit a patch.
         $query = db_select('users', 'u')->fields('u', array('uid'))->orderBy('u.access', 'DESC')->range(0, 9);
         $uids = $query->execute()->fetchCol();
         array_unshift($uids, 0);
         $accounts = user_load_multiple($uids);
         foreach ($accounts as $account) {
             $username = theme('username', array('account' => $account));
             $uid = $account->id();
             if ($uid == $user->id()) {
                 $username = '******' . $username . '</strong>';
             }
             $rows[] = array($username, array('id' => 'create-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('create', $node, $account, $langcode)))), array('id' => 'view-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('view', $node, $account, $langcode)))), array('id' => 'update-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('update', $node, $account, $langcode)))), array('id' => 'delete-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('delete', $node, $account, $langcode)))));
         }
         if (count($rows)) {
             $output['title'] = array('#prefix' => '<h2>', '#markup' => t('Access permissions by user for the %langname language', array('%langname' => $language->name)), '#postfix' => '</h2>');
             $output[] = array('#theme' => 'table', '#header' => $headers, '#rows' => $rows, '#attributes' => array('style' => 'text-align: left'));
             $output[] = array('#theme' => 'form_element', '#description' => t('(This table lists the most-recently active users. Hover your mouse over each result for more details.)'));
         }
     }
     return $output;
 }
 public function getExistingObject(NodeInterface $node, Context $context)
 {
     /* @var $node EntityNode */
     if (!$this->exists($node, $context)) {
         $context->logCritical(sprintf("%s: node type does not exist", $node->getPath()));
     }
     $existing = array_intersect_key((array) node_type_load($node->getName()), self::$defaults);
     $existing = array_diff($existing, self::$defaults);
     $settings = [];
     foreach (self::$settings as $key => $defaultValue) {
         $variable = 'node_' . $key . '_' . $node->getBundle();
         $value = variable_get($variable);
         if ($value != $defaultValue) {
             $settings[$key] = $value;
         }
     }
     if (!empty($settings)) {
         $existing['settings'] = $settings;
     }
     return $existing;
 }
 /**
  * Creates a new product class.
  *
  * Fix this after adding a proper API call for saving a product class.
  */
 protected function createProductClass($data = [])
 {
     $class = strtolower($this->randomMachineName(12));
     $edit = $data + array('type' => $class, 'name' => $class, 'description' => $this->randomMachineName(32), 'uc_product[product]' => TRUE);
     $this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type'));
     return node_type_load($class);
 }
Exemplo n.º 4
0
 /**
  * Creates a custom content type based on default settings.
  *
  * @param array $values
  *   An array of settings to change from the defaults.
  *   Example: 'type' => 'foo'.
  *
  * @return \Drupal\node\Entity\NodeType
  *   Created content type.
  */
 protected function drupalCreateContentType(array $values = array())
 {
     // Find a non-existent random type name.
     if (!isset($values['type'])) {
         do {
             $id = strtolower($this->randomMachineName(8));
         } while (node_type_load($id));
     } else {
         $id = $values['type'];
     }
     $values += array('type' => $id, 'name' => $id);
     $type = entity_create('node_type', $values);
     $status = $type->save();
     \Drupal::service('router.builder')->rebuild();
     $this->assertEqual($status, SAVED_NEW, String::format('Created content type %type.', array('%type' => $type->id())));
     return $type;
 }
 /**
  * Test our new content types.
  *
  * Tests for the following:
  *
  * - That our content types appear in the user interface.
  * - That our unlocked content type is unlocked.
  * - That our locked content type is locked.
  * - That we can create content using the user interface.
  * - That our created content does appear in the database.
  */
 public function testNodeTypes()
 {
     // Log in an admin user.
     $admin_user = $this->drupalCreateUser(array('administer content types'));
     $this->drupalLogin($admin_user);
     // Get a list of content types.
     $this->drupalGet('/admin/structure/types');
     // Verify that these content types show up in the user interface.
     $this->assertRaw('Example: Basic Content Type', 'Basic content type found.');
     $this->assertRaw('Example: Locked Content Type', 'Locked content type found.');
     // Check for the locked status of our content types.
     // $nodeType will be of type Drupal\node\NodeTypeInterface
     $node_type = node_type_load('basic_content_type');
     $this->assertTrue($node_type, 'basic_content_type exists.');
     if ($node_type) {
         $this->assertFalse($node_type->isLocked(), 'basic_content_type is not locked.');
     }
     $node_type = node_type_load('locked_content_type');
     $this->assertTrue($node_type, 'locked_content_type exists.');
     if ($node_type) {
         $this->assertEqual('locked_content_type', $node_type->isLocked(), 'locked_content_type is locked.');
     }
     // Log in a content creator.
     $creator_user = $this->drupalCreateUser(array('create basic_content_type content'));
     $this->drupalLogin($creator_user);
     // Create a node.
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName(8);
     $edit['body[0][value]'] = $this->randomMachineName(16);
     $this->drupalPostForm('/node/add/basic_content_type', $edit, t('Save'));
     // Check that the Basic page has been created.
     $this->assertRaw(t('!post %title has been created.', array('!post' => 'Example: Basic Content Type', '%title' => $edit['title[0][value]'])), 'Basic page created.');
     // Check that the node exists in the database.
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertTrue($node, 'Node found in database.');
 }
Exemplo n.º 6
0
 /**
  * Tests renaming and deleting a bundle.
  */
 public function testRenameDeleteBundle()
 {
     $this->installEntitySchema('node');
     // Create a node bundle, display and form display object.
     entity_create('node_type', array('type' => 'article'))->save();
     entity_get_display('node', 'article', 'default')->save();
     entity_get_form_display('node', 'article', 'default')->save();
     // Rename the article bundle and assert the entity display is renamed.
     $type = node_type_load('article');
     $type->old_type = 'article';
     $type->type = 'article_rename';
     $type->save();
     $old_display = entity_load('entity_view_display', 'node.article.default');
     $this->assertFalse((bool) $old_display);
     $old_form_display = entity_load('entity_form_display', 'node.article.default');
     $this->assertFalse((bool) $old_form_display);
     $new_display = entity_load('entity_view_display', 'node.article_rename.default');
     $this->assertEqual('article_rename', $new_display->bundle);
     $this->assertEqual('node.article_rename.default', $new_display->id);
     $new_form_display = entity_load('entity_form_display', 'node.article_rename.default');
     $this->assertEqual('article_rename', $new_form_display->bundle);
     $this->assertEqual('node.article_rename.default', $new_form_display->id);
     $expected_view_dependencies = array('config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), 'module' => array('entity_test', 'text', 'user'));
     // Check that the display has dependencies on the bundle, fields and the
     // modules that provide the formatters.
     $dependencies = $new_display->calculateDependencies();
     $this->assertEqual($expected_view_dependencies, $dependencies);
     // Check that the form display has dependencies on the bundle, fields and
     // the modules that provide the formatters.
     $dependencies = $new_form_display->calculateDependencies();
     $expected_form_dependencies = array('config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), 'module' => array('entity_reference', 'text'));
     $this->assertEqual($expected_form_dependencies, $dependencies);
     // Delete the bundle.
     $type->delete();
     $display = entity_load('entity_view_display', 'node.article_rename.default');
     $this->assertFalse((bool) $display);
     $form_display = entity_load('entity_form_display', 'node.article_rename.default');
     $this->assertFalse((bool) $form_display);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
 {
     $node_type = node_type_load($bundle);
     $fields = array();
     // When deleting a node type the corresponding node displays are deleted as
     // well. In order to be deleted, they need to be loaded first. Entity
     // displays, however, fetch the field definitions of the respective entity
     // type to fill in their defaults. Therefore this function ends up being
     // called with a non-existing bundle.
     // @todo Fix this in https://drupal.org/node/2248795
     if (!$node_type) {
         return $fields;
     }
     if (isset($node_type->title_label)) {
         $fields['title'] = clone $base_field_definitions['title'];
         $fields['title']->setLabel($node_type->title_label);
     }
     $options = $node_type->getModuleSettings('node')['options'];
     $fields['status'] = clone $base_field_definitions['status'];
     $fields['status']->setDefaultValue(!empty($options['status']) ? NODE_PUBLISHED : NODE_NOT_PUBLISHED);
     $fields['promote'] = clone $base_field_definitions['promote'];
     $fields['promote']->setDefaultValue(!empty($options['promote']) ? NODE_PROMOTED : NODE_NOT_PROMOTED);
     $fields['sticky'] = clone $base_field_definitions['sticky'];
     $fields['sticky']->setDefaultValue(!empty($options['sticky']) ? NODE_STICKY : NODE_NOT_STICKY);
     return $fields;
 }
Exemplo n.º 8
0
 /**
  * Create one node. Used by both batch and non-batch code branches.
  */
 protected function develGenerateContentAddNode(&$results)
 {
     if (!isset($results['time_range'])) {
         $results['time_range'] = 0;
     }
     $users = $results['users'];
     $node_type = array_rand(array_filter($results['node_types']));
     $type = node_type_load($node_type);
     $uid = $users[array_rand($users)];
     $edit_node = array('nid' => NULL, 'type' => $node_type, 'uid' => $uid, 'revision' => mt_rand(0, 1), 'status' => TRUE, 'promote' => mt_rand(0, 1), 'created' => REQUEST_TIME - mt_rand(0, $results['time_range']), 'langcode' => $this->getLangcode($results));
     // We should not use the random function if the value is not random
     if ($results['title_length'] < 2) {
         $edit_node['title'] = $this->createGreeking(1, TRUE);
     } else {
         $edit_node['title'] = $this->createGreeking(mt_rand(1, $results['title_length']), TRUE);
     }
     $node = entity_create('node', $edit_node);
     // A flag to let hook_node_insert() implementations know that this is a
     // generated node.
     $node->devel_generate = $results;
     // Populate all core fields on behalf of field.module
     DevelGenerateFieldBase::generateFields($node, 'node', $node->bundle());
     // See devel_generate_node_insert() for actions that happen before and after
     // this save.
     $node->save();
 }
Exemplo n.º 9
0
 /**
  * Drupal 6
  */
 protected function readDrupal7SiteProperties()
 {
     $entityInfo = entity_get_info();
     $this->entityTypes = array();
     foreach ($entityInfo as $entity_type => $entity_info) {
         if (in_array($entity_type, array('node', 'taxonomy_term'))) {
             foreach ($entity_info['bundles'] as $bundle => $bundleInfo) {
                 if ($instanceInfo = field_info_instances($entity_type, $bundle)) {
                     foreach ($instanceInfo as $instance) {
                         $this->instances[] = $this->processInstance($instance);
                     }
                 }
                 switch ($entity_type) {
                     case 'node':
                         $node_type = node_type_load($bundle);
                         $this->entityTypes[] = new NodeTypeBuilder($bundle, $bundleInfo['label'], $node_type->description);
                         break;
                     case 'taxonomy_term':
                         $vocabulary = taxonomy_vocabulary_machine_name_load($bundle);
                         $this->entityTypes[] = new VocabularyBuilder($bundle, $bundleInfo['label'], $vocabulary->description);
                         break;
                 }
             }
         }
     }
     $fieldInfo = field_info_fields();
     foreach ($fieldInfo as $fieldName => $info) {
         $this->fields[$fieldName] = new FieldBuilder($fieldName, $info['type']);
     }
     $this->parseDefinition();
 }