当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldConfig::setSetting方法代码示例

本文整理汇总了PHP中Drupal\field\Entity\FieldConfig::setSetting方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldConfig::setSetting方法的具体用法?PHP FieldConfig::setSetting怎么用?PHP FieldConfig::setSetting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\field\Entity\FieldConfig的用法示例。


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

示例1: testLinkTitle

 /**
  * Tests the link title settings of a link field.
  */
 function testLinkTitle()
 {
     $field_name = Unicode::strtolower($this->randomMachineName());
     // Create a field with settings to validate.
     $this->fieldStorage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'link'));
     $this->fieldStorage->save();
     $this->field = entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', 'label' => 'Read more about this entity', 'settings' => array('title' => DRUPAL_OPTIONAL, 'link_type' => LinkItemInterface::LINK_GENERIC)));
     $this->field->save();
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'link_default', 'settings' => array('placeholder_url' => 'http://example.com', 'placeholder_title' => 'Enter the text for this link')))->save();
     entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'link', 'label' => 'hidden'))->save();
     // Verify that the link text field works according to the field setting.
     foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $title_setting) {
         // Update the link title field setting.
         $this->field->setSetting('title', $title_setting);
         $this->field->save();
         // Display creation form.
         $this->drupalGet('entity_test/add');
         // Assert label is shown.
         $this->assertText('Read more about this entity');
         $this->assertFieldByName("{$field_name}[0][uri]", '', 'URL field found.');
         $this->assertRaw('placeholder="http://example.com"');
         if ($title_setting === DRUPAL_DISABLED) {
             $this->assertNoFieldByName("{$field_name}[0][title]", '', 'Link text field not found.');
             $this->assertNoRaw('placeholder="Enter the text for this link"');
         } else {
             $this->assertRaw('placeholder="Enter the text for this link"');
             $this->assertFieldByName("{$field_name}[0][title]", '', 'Link text field found.');
             if ($title_setting === DRUPAL_REQUIRED) {
                 // Verify that the link text is required, if the URL is non-empty.
                 $edit = array("{$field_name}[0][uri]" => 'http://www.example.com');
                 $this->drupalPostForm(NULL, $edit, t('Save'));
                 $this->assertText(t('@name field is required.', array('@name' => t('Link text'))));
                 // Verify that the link text is not required, if the URL is empty.
                 $edit = array("{$field_name}[0][uri]" => '');
                 $this->drupalPostForm(NULL, $edit, t('Save'));
                 $this->assertNoText(t('@name field is required.', array('@name' => t('Link text'))));
                 // Verify that a URL and link text meets requirements.
                 $this->drupalGet('entity_test/add');
                 $edit = array("{$field_name}[0][uri]" => 'http://www.example.com', "{$field_name}[0][title]" => 'Example');
                 $this->drupalPostForm(NULL, $edit, t('Save'));
                 $this->assertNoText(t('@name field is required.', array('@name' => t('Link text'))));
             }
         }
     }
     // Verify that a link without link text is rendered using the URL as text.
     $value = 'http://www.example.com/';
     $edit = array("{$field_name}[0][uri]" => $value, "{$field_name}[0][title]" => '');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     preg_match('|entity_test/manage/(\\d+)|', $this->url, $match);
     $id = $match[1];
     $this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
     $this->renderTestEntity($id);
     $expected_link = \Drupal::l($value, Url::fromUri($value));
     $this->assertRaw($expected_link);
     // Verify that a link with text is rendered using the link text.
     $title = $this->randomMachineName();
     $edit = array("{$field_name}[0][title]" => $title);
     $this->drupalPostForm("entity_test/manage/{$id}", $edit, t('Save'));
     $this->assertText(t('entity_test @id has been updated.', array('@id' => $id)));
     $this->renderTestEntity($id);
     $expected_link = \Drupal::l($title, Url::fromUri($value));
     $this->assertRaw($expected_link);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:66,代码来源:LinkFieldTest.php


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