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

PHP Entity\ContentLanguageSettings类代码示例

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

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



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

示例1: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $vocabulary = $this->entity;
     if ($vocabulary->isNew()) {
         $form['#title'] = $this->t('Add vocabulary');
     } else {
         $form['#title'] = $this->t('Edit vocabulary');
     }
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Name'), '#default_value' => $vocabulary->label(), '#maxlength' => 255, '#required' => TRUE);
     $form['vid'] = array('#type' => 'machine_name', '#default_value' => $vocabulary->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('exists' => array($this, 'exists'), 'source' => array('name')));
     $form['description'] = array('#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $vocabulary->getDescription());
     // $form['langcode'] is not wrapped in an
     // if ($this->moduleHandler->moduleExists('language')) check because the
     // language_select form element works also without the language module being
     // installed. https://www.drupal.org/node/1749954 documents the new element.
     $form['langcode'] = array('#type' => 'language_select', '#title' => $this->t('Vocabulary language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $vocabulary->language()->getId());
     if ($this->moduleHandler->moduleExists('language')) {
         $form['default_terms_language'] = array('#type' => 'details', '#title' => $this->t('Terms language'), '#open' => TRUE);
         $form['default_terms_language']['default_language'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'taxonomy_term', 'bundle' => $vocabulary->id()), '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()));
     }
     // Set the hierarchy to "multiple parents" by default. This simplifies the
     // vocabulary form and standardizes the term form.
     $form['hierarchy'] = array('#type' => 'value', '#value' => '0');
     $form = parent::form($form, $form_state);
     return $this->protectBundleIdElement($form);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:29,代码来源:VocabularyForm.php


示例2: testLanguageContentWithNoLanguageLock

 /**
  * Tests migration of content language settings when there is no language lock.
  */
 public function testLanguageContentWithNoLanguageLock()
 {
     // Assert that a we can assign a language.
     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'employee');
     $this->assertSame($config->getDefaultLangcode(), 'current_interface');
     $this->assertTrue($config->isLanguageAlterable());
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:MigrateLanguageContentSettingsTest.php


示例3: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $comment_type = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, '#default_value' => $comment_type->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $comment_type->id(), '#machine_name' => array('exists' => '\\Drupal\\comment\\Entity\\CommentType::load'), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$comment_type->isNew());
     $form['description'] = array('#type' => 'textarea', '#default_value' => $comment_type->getDescription(), '#description' => t('Describe this comment type. The text will be displayed on the <em>Comment types</em> administration overview page.'), '#title' => t('Description'));
     if ($comment_type->isNew()) {
         $options = array();
         foreach ($this->entityManager->getDefinitions() as $entity_type) {
             // Only expose entities that have field UI enabled, only those can
             // get comment fields added in the UI.
             if ($entity_type->get('field_ui_base_route')) {
                 $options[$entity_type->id()] = $entity_type->getLabel();
             }
         }
         $form['target_entity_type_id'] = array('#type' => 'select', '#default_value' => $comment_type->getTargetEntityTypeId(), '#title' => t('Target entity type'), '#options' => $options, '#description' => t('The target entity type can not be changed after the comment type has been created.'));
     } else {
         $form['target_entity_type_id_display'] = array('#type' => 'item', '#markup' => $this->entityManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), '#title' => t('Target entity type'));
     }
     if ($this->moduleHandler->moduleExists('content_translation')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', $comment_type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'comment', 'bundle' => $comment_type->id()), '#default_value' => $language_configuration);
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     return $form;
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:33,代码来源:CommentTypeForm.php


示例4: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */
     $product_type = $this->entity;
     $variation_types = $this->variationTypeStorage->loadMultiple();
     $variation_types = array_map(function ($variation_type) {
         return $variation_type->label();
     }, $variation_types);
     // Create an empty product to get the default status value.
     // @todo Clean up once https://www.drupal.org/node/2318187 is fixed.
     if ($this->operation == 'add') {
         $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->uuid()]);
     } else {
         $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->id()]);
     }
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $product_type->label(), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $product_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_product\\Entity\\ProductType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['description'] = ['#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $product_type->getDescription()];
     $form['variationType'] = ['#type' => 'select', '#title' => $this->t('Product variation type'), '#default_value' => $product_type->getVariationType(), '#options' => $variation_types, '#required' => TRUE];
     $form['product_status'] = ['#type' => 'checkbox', '#title' => t('Publish new products of this type by default.'), '#default_value' => $product->isPublished()];
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
         $form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_product', 'bundle' => $product_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_product', $product_type->id())];
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     return $this->protectBundleIdElement($form);
 }
开发者ID:marmouset,项目名称:drupal,代码行数:31,代码来源:ProductTypeForm.php


示例5: setUp

 protected function setUp()
 {
     parent::setUp();
     // Set up an additional language.
     $this->langcodes = array(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'es');
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Create a content type.
     $this->bundle = $this->randomMachineName();
     $this->contentType = $this->drupalCreateContentType(array('type' => $this->bundle));
     // Enable translation for the current entity type and ensure the change is
     // picked up.
     \Drupal::service('content_translation.manager')->setEnabled('node', $this->bundle, TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedBundles();
     \Drupal::service('router.builder')->rebuild();
     // Add a translatable field to the content type.
     entity_create('field_storage_config', array('field_name' => 'field_test_text', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, 'translatable' => TRUE))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_text', 'bundle' => $this->bundle, 'label' => 'Test text-field'))->save();
     entity_get_form_display('node', $this->bundle, 'default')->setComponent('field_test_text', array('type' => 'text_textfield', 'weight' => 0))->save();
     // Enable content translation.
     ContentLanguageSettings::loadByEntityTypeBundle('node', $this->bundle)->setLanguageAlterable(TRUE)->setDefaultLangcode(\Drupal::languageManager()->getDefaultLanguage()->getId())->save();
     // Create a translator user.
     $permissions = array('access contextual links', 'administer nodes', "edit any {$this->bundle} content", 'translate any entity');
     $this->translator = $this->drupalCreateUser($permissions);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:25,代码来源:ContentTranslationContextualLinksTest.php


示例6: testVocabularyDefaultLanguageForTerms

 /**
  * Tests term language settings for vocabulary terms are saved and updated.
  */
 function testVocabularyDefaultLanguageForTerms()
 {
     // Add a new vocabulary and check that the default language settings are for
     // the terms are saved.
     $edit = array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'default_language[langcode]' => 'bb', 'default_language[language_alterable]' => TRUE);
     $vid = $edit['vid'];
     $this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
     // Check that the vocabulary was actually created.
     $this->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
     $this->assertResponse(200, 'The vocabulary has been created.');
     // Check that the language settings were saved.
     $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
     $this->assertEqual($language_settings->getDefaultLangcode(), 'bb', 'The langcode was saved.');
     $this->assertTrue($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');
     // Check that the correct options are selected in the interface.
     $this->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.');
     $this->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.');
     // Edit the vocabulary and check that the new settings are updated.
     $edit = array('default_language[langcode]' => 'aa', 'default_language[language_alterable]' => FALSE);
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
     // And check again the settings and also the interface.
     $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
     $this->assertEqual($language_settings->getDefaultLangcode(), 'aa', 'The langcode was saved.');
     $this->assertFalse($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');
     $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
     $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.');
     $this->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.');
     // Check that language settings are changed after editing vocabulary.
     $edit = array('name' => $this->randomMachineName(), 'default_language[langcode]' => 'authors_default', 'default_language[language_alterable]' => FALSE);
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
     // Check that we have the new settings.
     $new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
     $this->assertEqual($new_settings->getDefaultLangcode(), 'authors_default', 'The langcode was saved.');
     $this->assertFalse($new_settings->isLanguageAlterable(), 'The new visibility setting was saved.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:38,代码来源:VocabularyLanguageTest.php


示例7: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type */
     $variation_type = $this->entity;
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $variation_type->label(), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $variation_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_product\\Entity\\ProductVariationType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['generateTitle'] = ['#type' => 'checkbox', '#title' => t('Generate variation titles based on attribute values.'), '#default_value' => $variation_type->shouldGenerateTitle()];
     if (\Drupal::moduleHandler()->moduleExists('commerce_order')) {
         // Prepare a list of line item types used to purchase product variations.
         $line_item_type_storage = $this->entityTypeManager->getStorage('commerce_line_item_type');
         $line_item_types = $line_item_type_storage->loadMultiple();
         $line_item_types = array_filter($line_item_types, function ($line_item_type) {
             return $line_item_type->getPurchasableEntityTypeId() == 'commerce_product_variation';
         });
         $line_item_types = array_map(function ($line_item_type) {
             return $line_item_type->label();
         }, $line_item_types);
         $form['lineItemType'] = ['#type' => 'select', '#title' => $this->t('Line item type'), '#default_value' => $variation_type->getLineItemTypeId(), '#options' => $line_item_types, '#empty_value' => '', '#required' => TRUE];
     }
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
         $form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_product_variation', 'bundle' => $variation_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_product_variation', $variation_type->id())];
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     return $this->protectBundleIdElement($form);
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:30,代码来源:ProductVariationTypeForm.php


示例8: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');
     $form['lang_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'entity_test', 'bundle' => 'some_bundle'), '#default_value' => $conf);
     $form['submit'] = array('#type' => 'submit', '#value' => 'Save');
     $form['#submit'][] = 'language_configuration_element_submit';
     return $form;
 }
开发者ID:318io,项目名称:318-io,代码行数:11,代码来源:LanguageConfigurationElement.php


示例9: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $store_type = $this->entity;
     $form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $store_type->label(), '#description' => $this->t('Label for the store type.'), '#required' => TRUE];
     $form['id'] = ['#type' => 'machine_name', '#default_value' => $store_type->id(), '#machine_name' => ['exists' => '\\Drupal\\commerce_store\\Entity\\StoreType::load'], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH];
     $form['description'] = ['#type' => 'textfield', '#title' => $this->t('Description'), '#default_value' => $store_type->getDescription()];
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = ['#type' => 'details', '#title' => $this->t('Language settings'), '#group' => 'additional_settings'];
         $form['language']['language_configuration'] = ['#type' => 'language_configuration', '#entity_information' => ['entity_type' => 'commerce_store', 'bundle' => $store_type->id()], '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('commerce_store', $store_type->id())];
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     return $this->protectBundleIdElement($form);
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:17,代码来源:StoreTypeForm.php


示例10: testLanguageContent

 /**
  * Tests migration of content language settings.
  */
 public function testLanguageContent()
 {
     // Assert that a translatable content is still translatable.
     $config = $this->config('language.content_settings.node.blog');
     $this->assertIdentical($config->get('target_entity_type_id'), 'node');
     $this->assertIdentical($config->get('target_bundle'), 'blog');
     $this->assertIdentical($config->get('default_langcode'), 'current_interface');
     $this->assertFalse($config->get('language_alterable'));
     $this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
     // Assert that a non-translatable content is not translatable.
     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
     $this->assertTrue($config->isDefaultConfiguration());
     $this->assertFalse($config->isLanguageAlterable());
     $this->assertSame($config->getDefaultLangcode(), 'site_default');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:18,代码来源:MigrateLanguageContentSettingsTest.php


示例11: testMenuLanguage

 /**
  * Tests menu language settings and the defaults for menu link items.
  */
 function testMenuLanguage()
 {
     // Create a test menu to test the various language-related settings.
     // Machine name has to be lowercase.
     $menu_name = Unicode::strtolower($this->randomMachineName(16));
     $label = $this->randomString();
     $edit = array('id' => $menu_name, 'description' => '', 'label' => $label, 'langcode' => 'aa');
     $this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
     ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content')->setDefaultLangcode('bb')->setLanguageAlterable(TRUE)->save();
     // Check menu language.
     $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The menu language was correctly selected.');
     // Test menu link language.
     $link_path = '/';
     // Add a menu link.
     $link_title = $this->randomString();
     $edit = array('title[0][value]' => $link_title, 'link[0][uri]' => $link_path);
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}/add", $edit, t('Save'));
     // Check the link was added with the correct menu link default language.
     $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $link_title));
     $menu_link = reset($menu_links);
     $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'route_name' => '<front>', 'langcode' => 'bb'));
     // Edit menu link default, changing it to cc.
     ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content')->setDefaultLangcode('cc')->setLanguageAlterable(TRUE)->save();
     // Add a menu link.
     $link_title = $this->randomString();
     $edit = array('title[0][value]' => $link_title, 'link[0][uri]' => $link_path);
     $this->drupalPostForm("admin/structure/menu/manage/{$menu_name}/add", $edit, t('Save'));
     // Check the link was added with the correct new menu link default language.
     $menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $link_title));
     $menu_link = reset($menu_links);
     $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'route_name' => '<front>', 'langcode' => 'cc'));
     // Now change the language of the new link to 'bb'.
     $edit = array('langcode[0][value]' => 'bb');
     $this->drupalPostForm('admin/structure/menu/item/' . $menu_link->id() . '/edit', $edit, t('Save'));
     $this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'route_name' => '<front>', 'langcode' => 'bb'));
     // Saving menu link items ends up on the edit menu page. To check the menu
     // link has the correct language default on edit, go to the menu link edit
     // page first.
     $this->drupalGet('admin/structure/menu/item/' . $menu_link->id() . '/edit');
     // Check that the language selector has the correct default value.
     $this->assertOptionSelected('edit-langcode-0-value', 'bb', 'The menu link language was correctly selected.');
     // Edit menu to hide the language select on menu link item add.
     ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content')->setDefaultLangcode('cc')->setLanguageAlterable(FALSE)->save();
     // Check that the language selector is not available on menu link add page.
     $this->drupalGet("admin/structure/menu/manage/{$menu_name}/add");
     $this->assertNoField('edit-langcode-0-value', 'The language selector field was hidden the page');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:50,代码来源:MenuLanguageTest.php


示例12: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     /* @var \Drupal\block_content\BlockContentTypeInterface $block_type */
     $block_type = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, '#default_value' => $block_type->label(), '#description' => t("Provide a label for this block type to help identify it in the administration pages."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $block_type->id(), '#machine_name' => array('exists' => '\\Drupal\\block_content\\Entity\\BlockContentType::load'), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$block_type->isNew());
     $form['description'] = array('#type' => 'textarea', '#default_value' => $block_type->getDescription(), '#description' => t('Enter a description for this block type.'), '#title' => t('Description'));
     $form['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $block_type->shouldCreateNewRevision(), '#description' => t('Create a new revision by default for this block type.'));
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('block_content', $block_type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'block_content', 'bundle' => $block_type->id()), '#default_value' => $language_configuration);
         $form['#submit'][] = 'language_configuration_element_submit';
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
     return $form;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:BlockContentTypeForm.php


示例13: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $type = $this->entity;
     if ($this->operation == 'add') {
         $form['#title'] = $this->t('Add content type');
         $fields = $this->entityManager->getBaseFieldDefinitions('node');
         // Create a node with a fake bundle using the type's UUID so that we can
         // get the default values for workflow settings.
         // @todo Make it possible to get default values without an entity.
         //   https://www.drupal.org/node/2318187
         $node = $this->entityManager->getStorage('node')->create(array('type' => $type->uuid()));
     } else {
         $form['#title'] = $this->t('Edit %label content type', array('%label' => $type->label()));
         $fields = $this->entityManager->getFieldDefinitions('node', $type->id());
         // Create a node to get the current values for workflow settings fields.
         $node = $this->entityManager->getStorage('node')->create(array('type' => $type->id()));
     }
     $form['name'] = array('#title' => t('Name'), '#type' => 'textfield', '#default_value' => $type->label(), '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the <em>Add content</em> page. This name must be unique.'), '#required' => TRUE, '#size' => 30);
     $form['type'] = array('#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => $type->isLocked(), '#machine_name' => array('exists' => ['Drupal\\node\\Entity\\NodeType', 'load'], 'source' => array('name')), '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array('%node-add' => t('Add content'))));
     $form['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => $type->getDescription(), '#description' => t('This text will be displayed on the <em>Add new content</em> page.'));
     $form['additional_settings'] = array('#type' => 'vertical_tabs', '#attached' => array('library' => array('node/drupal.content_types')));
     $form['submission'] = array('#type' => 'details', '#title' => t('Submission form settings'), '#group' => 'additional_settings', '#open' => TRUE);
     $form['submission']['title_label'] = array('#title' => t('Title field label'), '#type' => 'textfield', '#default_value' => $fields['title']->getLabel(), '#required' => TRUE);
     $form['submission']['preview_mode'] = array('#type' => 'radios', '#title' => t('Preview before submitting'), '#default_value' => $type->getPreviewMode(), '#options' => array(DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), DRUPAL_REQUIRED => t('Required')));
     $form['submission']['help'] = array('#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => $type->getHelp(), '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'));
     $form['workflow'] = array('#type' => 'details', '#title' => t('Publishing options'), '#group' => 'additional_settings');
     $workflow_options = array('status' => $node->status->value, 'promote' => $node->promote->value, 'sticky' => $node->sticky->value, 'revision' => $type->isNewRevision());
     // Prepare workflow options to be used for 'checkboxes' form element.
     $keys = array_keys(array_filter($workflow_options));
     $workflow_options = array_combine($keys, $keys);
     $form['workflow']['options'] = array('#type' => 'checkboxes', '#title' => t('Default options'), '#default_value' => $workflow_options, '#options' => array('status' => t('Published'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')), '#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'));
     if ($this->moduleHandler->moduleExists('language')) {
         $form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
         $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $type->id());
         $form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'node', 'bundle' => $type->id()), '#default_value' => $language_configuration);
     }
     $form['display'] = array('#type' => 'details', '#title' => t('Display settings'), '#group' => 'additional_settings');
     $form['display']['display_submitted'] = array('#type' => 'checkbox', '#title' => t('Display author and date information'), '#default_value' => $type->displaySubmitted(), '#description' => t('Author username and publish date will be displayed.'));
     return $this->protectBundleIdElement($form);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:44,代码来源:NodeTypeForm.php


示例14: setUpLanguages

 /**
  * Set up configuration for multiple languages.
  */
 function setUpLanguages()
 {
     // Add languages.
     $this->defaultLanguage = 'en';
     $this->secondaryLanguage = 'es';
     $this->addLanguage($this->secondaryLanguage);
     // Display the language widget.
     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'simplenews_issue');
     $config->setLanguageAlterable(TRUE);
     $config->save();
     // Make Simplenews issue translatable.
     \Drupal::service('content_translation.manager')->setEnabled('node', 'simplenews_issue', TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
     \Drupal::service('router.builder')->rebuild();
     \Drupal::service('entity.definition_update_manager')->applyUpdates();
     // Make Simplenews issue body translatable.
     $field = FieldConfig::loadByName('node', 'simplenews_issue', 'body');
     $field->setTranslatable(TRUE);
     $field->save();
     $this->rebuildContainer();
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:25,代码来源:SimplenewsI18nTest.php


示例15: createContentType

 /**
  * Creates a new node content type.
  *
  * @param string $name
  *   The content type name.
  * @param string $langcode
  *   Default language code of the nodes of this type.
  */
 protected function createContentType($name, $langcode)
 {
     $content_type = $this->container->get('entity.manager')->getStorage('node_type')->create(array('name' => 'Test ' . $name, 'title_label' => 'Title', 'type' => $name, 'create_body' => FALSE));
     $content_type->save();
     ContentLanguageSettings::loadByEntityTypeBundle('node', $name)->setLanguageAlterable(FALSE)->setDefaultLangcode($langcode)->save();
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:14,代码来源:EntityDefaultLanguageTest.php


示例16: hook_entity_extra_field_info

/**
 * Exposes "pseudo-field" components on content entities.
 *
 * Field UI's "Manage fields" and "Manage display" pages let users re-order
 * fields, but also non-field components. For nodes, these include elements
 * exposed by modules through hook_form_alter(), for instance.
 *
 * Content entities or modules that want to have their components supported
 * should expose them using this hook. The user-defined settings (weight,
 * visible) are automatically applied when entities or entity forms are
 * rendered.
 *
 * @see hook_entity_extra_field_info_alter()
 *
 * @return array
 *   The array structure is identical to that of the return value of
 *   \Drupal\Core\Entity\EntityManagerInterface::getExtraFields().
 */
function hook_entity_extra_field_info()
{
    $extra = array();
    $module_language_enabled = \Drupal::moduleHandler()->moduleExists('language');
    $description = t('Node module element');
    foreach (NodeType::loadMultiple() as $bundle) {
        // Add also the 'language' select if Language module is enabled and the
        // bundle has multilingual support.
        // Visibility of the ordering of the language selector is the same as on the
        // node/add form.
        if ($module_language_enabled) {
            $configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundle->type);
            if ($configuration->isLanguageAlterable()) {
                $extra['node'][$bundle->type]['form']['language'] = array('label' => t('Language'), 'description' => $description, 'weight' => 0);
            }
        }
        $extra['node'][$bundle->type]['display']['language'] = array('label' => t('Language'), 'description' => $description, 'weight' => 0, 'visible' => FALSE);
    }
    return $extra;
}
开发者ID:dev981,项目名称:gaptest,代码行数:38,代码来源:entity.api.php


示例17: testSettingsUI

 /**
  * Tests that the settings UI works as expected.
  */
 function testSettingsUI()
 {
     // Check for the content_translation_menu_links_discovered_alter() changes.
     $this->drupalGet('admin/config');
     $this->assertLink('Content language and translation');
     $this->assertText('Configure language and translation support for content.');
     // Test that the translation settings are ignored if the bundle is marked
     // translatable but the entity type is not.
     $edit = array('settings[comment][comment_article][translatable]' => TRUE);
     $this->assertSettings('comment', NULL, FALSE, $edit);
     // Test that the translation settings are ignored if only a field is marked
     // as translatable and not the related entity type and bundle.
     $edit = array('settings[comment][comment_article][fields][comment_body]' => TRUE);
     $this->assertSettings('comment', NULL, FALSE, $edit);
     // Test that the translation settings are not stored if an entity type and
     // bundle are marked as translatable but no field is.
     $edit = array('entity_types[comment]' => TRUE, 'settings[comment][comment_article][translatable]' => TRUE, 'settings[comment][comment_article][fields][changed]' => FALSE, 'settings[comment][comment_article][fields][created]' => FALSE, 'settings[comment][comment_article][fields][homepage]' => FALSE, 'settings[comment][comment_article][fields][hostname]' => FALSE, 'settings[comment][comment_article][fields][mail]' => FALSE, 'settings[comment][comment_article][fields][name]' => FALSE, 'settings[comment][comment_article][fields][status]' => FALSE, 'settings[comment][comment_article][fields][subject]' => FALSE, 'settings[comment][comment_article][fields][uid]' => FALSE);
     $this->assertSettings('comment', 'comment_article', FALSE, $edit);
     $xpath_err = '//div[contains(@class, "error")]';
     $this->assertTrue($this->xpath($xpath_err), 'Enabling translation only for entity bundles generates a form error.');
     // Test that the translation settings are not stored if a non-configurable
     // language is set as default and the language selector is hidden.
     $edit = array('entity_types[comment]' => TRUE, 'settings[comment][comment_article][settings][language][langcode]' => Language::LANGCODE_NOT_SPECIFIED, 'settings[comment][comment_article][settings][language][language_alterable]' => FALSE, 'settings[comment][comment_article][translatable]' => TRUE, 'settings[comment][comment_article][fields][comment_body]' => TRUE);
     $this->assertSettings('comment', 'comment_article', FALSE, $edit);
     $this->assertTrue($this->xpath($xpath_err), 'Enabling translation with a fixed non-configurable language generates a form error.');
     // Test that a field shared among different bundles can be enabled without
     // needing to make all the related bundles translatable.
     $edit = array('entity_types[comment]' => TRUE, 'settings[comment][comment_article][settings][language][langcode]' => 'current_interface', 'settings[comment][comment_article][settings][language][language_alterable]' => TRUE, 'settings[comment][comment_article][translatable]' => TRUE, 'settings[comment][comment_article][fields][comment_body]' => TRUE, 'settings[comment][comment_article][fields][subject]' => FALSE, 'settings[comment][comment][fields][subject]' => FALSE);
     $this->assertSettings('comment', 'comment_article', TRUE, $edit);
     $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['comment_body'];
     $this->assertTrue($definition->isTranslatable(), 'Article comment body is translatable.');
     $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['subject'];
     $this->assertFalse($definition->isTranslatable(), 'Article comment subject is not translatable.');
     $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['comment_body'];
     $this->assertFalse($definition->isTranslatable(), 'Page comment body is not translatable.');
     $definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['subject'];
     $this->assertFalse($definition->isTranslatable(), 'Page comment subject is not translatable.');
     // Test that translation can be enabled for base fields.
     $edit = array('entity_types[entity_test_mul]' => TRUE, 'settings[entity_test_mul][entity_test_mul][translatable]' => TRUE, 'settings[entity_test_mul][entity_test_mul][fields][name]' => TRUE, 'settings[entity_test_mul][entity_test_mul][fields][user_id]' => FALSE);
     $this->assertSettings('entity_test_mul', 'entity_test_mul', TRUE, $edit);
     $field_override = BaseFieldOverride::loadByName('entity_test_mul', 'entity_test_mul', 'name');
     $this->assertTrue($field_override->isTranslatable(), 'Base fields can be overridden with a base field bundle override entity.');
     $definitions = $this->entityManager()->getFieldDefinitions('entity_test_mul', 'entity_test_mul');
     $this->assertTrue($definitions['name']->isTranslatable() && !$definitions['user_id']->isTranslatable(), 'Base field bundle overrides were correctly altered.');
     // Test that language settings are correctly stored.
     $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_article');
     $this->assertEqual($language_configuration->getDefaultLangcode(), 'current_interface', 'The default language for article comments is set to the interface text language selected for page.');
     $this->assertTrue($language_configuration->isLanguageAlterable(), 'The language selector for article comments is shown.');
     // Verify language widget appears on comment type form.
     $this->drupalGet('admin/structure/comment/manage/comment_article');
     $this->assertField('language_configuration[content_translation]');
     $this->assertFieldChecked('edit-language-configuration-content-translation');
     // Verify that translation may be enabled for the article content type.
     $edit = array('language_configuration[content_translation]' => TRUE);
     // Make sure the checkbox is available and not checked by default.
     $this->drupalGet('admin/structure/types/manage/article');
     $this->assertField('language_configuration[content_translation]');
     $this->assertNoFieldChecked('edit-language-configuration-content-translation');
     $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
     $this->d 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP migrate\MigrateExecutable类代码示例发布时间:2022-05-23
下一篇:
PHP Entity\ConfigurableLanguage类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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