/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, NodeTypeInterface $node_type = NULL)
 {
     $this->attributeTable = 'uc_class_attributes';
     $this->optionTable = 'uc_class_attribute_options';
     $this->idField = 'pcid';
     $this->idValue = $node_type->id();
     $attributes = uc_class_get_attributes($node_type->id());
     return parent::buildForm($form, $form_state, $attributes);
 }
 /**
  * Checks access to the node add page for the node type.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param \Drupal\node\NodeTypeInterface $node_type
  *   (optional) The node type. If not specified, access is allowed if there
  *   exists at least one node type for which the user may create a node.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(AccountInterface $account, NodeTypeInterface $node_type = NULL)
 {
     $access_controller = $this->entityManager->getAccessController('node');
     // If checking whether a node of a particular type may be created.
     if ($node_type) {
         return $access_controller->createAccess($node_type->id(), $account) ? static::ALLOW : static::DENY;
     }
     // If checking whether a node of any type may be created.
     foreach (node_permissions_get_configured_types() as $node_type) {
         if ($access_controller->createAccess($node_type->id(), $account)) {
             return static::ALLOW;
         }
     }
     return static::DENY;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create content type with unlimited text field.
     $this->nodeType = $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
     // Create the unlimited text field.
     $this->fieldName = 'field_views_testing_group_rows';
     $this->fieldStorage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => 'node', 'type' => 'text', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED]);
     $this->fieldStorage->save();
     // Create an instance of the text field on the content type.
     $this->field = FieldConfig::create(['field_storage' => $this->fieldStorage, 'bundle' => $this->nodeType->id()]);
     $this->field->save();
     $edit = ['title' => $this->randomMachineName(), $this->fieldName => ['a', 'b', 'c']];
     $this->drupalCreateNode($edit);
 }
Example #4
0
 /**
  * Tests that the "tagged with" form element only shows for node types that support it.
  */
 function testTaggedWithByNodeType()
 {
     // The tagging field is associated with one of our node types only. So the
     // "tagged with" form element on the view wizard should appear on the form
     // by default (when the wizard is configured to display all content) and
     // also when the node type that has the tagging field is selected, but not
     // when the node type that doesn't have the tagging field is selected.
     $tags_xpath = '//input[@name="show[tagged_with]"]';
     $this->drupalGet('admin/structure/views/add');
     $this->assertFieldByXpath($tags_xpath);
     $view['show[type]'] = $this->nodeTypeWithTags->id();
     $this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
     $this->assertFieldByXpath($tags_xpath);
     $view['show[type]'] = $this->nodeTypeWithoutTags->id();
     $this->drupalPostForm(NULL, $view, t('Update "of type" choice'));
     $this->assertNoFieldByXpath($tags_xpath);
     // If we add an instance of the tagging field to the second node type, the
     // "tagged with" form element should not appear for it too.
     entity_create('field_config', array('field_name' => $this->tagFieldName, 'entity_type' => 'node', 'bundle' => $this->nodeTypeWithoutTags->id(), 'settings' => array('handler' => 'default', 'handler_settings' => array('target_bundles' => array($this->tagVocabulary->id() => $this->tagVocabulary->id()), 'auto_create' => TRUE))))->save();
     entity_get_form_display('node', $this->nodeTypeWithoutTags->id(), 'default')->setComponent($this->tagFieldName, array('type' => 'entity_reference_autocomplete_tags'))->save();
     $view['show[type]'] = $this->nodeTypeWithTags->id();
     $this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
     $this->assertFieldByXpath($tags_xpath);
     $view['show[type]'] = $this->nodeTypeWithoutTags->id();
     $this->drupalPostForm(NULL, $view, t('Update "of type" choice'));
     $this->assertFieldByXpath($tags_xpath);
 }
 /**
  * Checks access to the node add page for the node type.
  *
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param \Drupal\node\NodeTypeInterface $node_type
  *   (optional) The node type. If not specified, access is allowed if there
  *   exists at least one node type for which the user may create a node.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(AccountInterface $account, NodeTypeInterface $node_type = NULL)
 {
     $access_control_handler = $this->entityManager->getAccessControlHandler('node');
     // If checking whether a node of a particular type may be created.
     if ($account->hasPermission('administer content types')) {
         return AccessResult::allowed()->cachePerRole();
     }
     if ($node_type) {
         return $access_control_handler->createAccess($node_type->id(), $account, [], TRUE);
     }
     // If checking whether a node of any type may be created.
     foreach ($this->entityManager->getStorage('node_type')->loadMultiple() as $node_type) {
         if (($access = $access_control_handler->createAccess($node_type->id(), $account, [], TRUE)) && $access->isAllowed()) {
             return $access;
         }
     }
     // No opinion.
     return AccessResult::neutral();
 }
Example #6
0
 /**
  * The _title_callback for the node.add route.
  *
  * @param \Drupal\node\NodeTypeInterface $node_type
  *   The current node.
  *
  * @return string
  *   The page title.
  */
 public function addPageTitle(NodeTypeInterface $node_type)
 {
     return $this->t('Create @name', array('@name' => $node_type->label()));
 }