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


PHP FieldConfig::label方法代码示例

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


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

示例1: testBooleanField

 /**
  * Tests boolean field.
  */
 function testBooleanField()
 {
     $on = $this->randomMachineName();
     $off = $this->randomMachineName();
     $label = $this->randomMachineName();
     // Create a field with settings to validate.
     $field_name = drupal_strtolower($this->randomMachineName());
     $this->field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'boolean', 'settings' => array('on_label' => $on, 'off_label' => $off)));
     $this->field_storage->save();
     $this->field = FieldConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE));
     $this->field->save();
     // Create a form display for the default form mode.
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox'))->save();
     // Create a display for the full view mode.
     entity_get_display('entity_test', 'entity_test', 'full')->setComponent($field_name, array('type' => 'boolean'))->save();
     // Display creation form.
     $this->drupalGet('entity_test/add');
     $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
     $this->assertRaw($on);
     // Submit and ensure it is accepted.
     $edit = array("{$field_name}[value]" => 1);
     $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)));
     // Verify that boolean value is displayed.
     $entity = entity_load('entity_test', $id);
     $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
     $content = $display->build($entity);
     $this->drupalSetContent(drupal_render($content));
     $this->assertRaw('<div class="field-item">' . $on . '</div>');
     // Test the display_label option.
     entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($field_name, array('type' => 'boolean_checkbox', 'settings' => array('display_label' => TRUE)))->save();
     $this->drupalGet('entity_test/add');
     $this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
     $this->assertNoRaw($on);
     $this->assertText($this->field->label());
     // Go to the form display page and check if the default settings works as
     // expected.
     $fieldEditUrl = 'entity_test/structure/entity_test/form-display';
     $this->drupalGet($fieldEditUrl);
     // Click on the widget settings button to open the widget settings form.
     $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
     $this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox available.'));
     // Enable setting.
     $edit = array('fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1);
     $this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update");
     $this->drupalPostForm(NULL, NULL, 'Save');
     // Go again to the form display page and check if the setting
     // is stored and has the expected effect.
     $this->drupalGet($fieldEditUrl);
     $this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.');
     $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit");
     $this->assertText('Use field label instead of the "On label" as label', t('Display setting checkbox is available'));
     $this->assertFieldByXPath('*//input[@id="edit-fields-' . $field_name . '-settings-edit-form-settings-display-label" and @value="1"]', TRUE, t('Display label changes label of the checkbox'));
     // Test the boolean field settings.
     $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name . '/storage');
     $this->assertFieldById('edit-field-storage-settings-on-label', $on);
     $this->assertFieldById('edit-field-storage-settings-off-label', $off);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:63,代码来源:BooleanFieldTest.php

示例2: testEntityReferenceDisplay

 /**
  * Tests the entity reference display plugin.
  */
 public function testEntityReferenceDisplay()
 {
     // Add the new field to the fields.
     $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/field', ['name[entity_test__' . $this->fieldName . '.' . $this->fieldName . ']' => TRUE], t('Add and configure fields'));
     $this->drupalPostForm(NULL, [], t('Apply'));
     // Test that the right fields are shown on the display settings form.
     $this->drupalGet('admin/structure/views/nojs/display/test_display_entity_reference/entity_reference_1/style_options');
     $this->assertText('Test entity: Name');
     $this->assertText('Test entity: ' . $this->field->label());
     // Add the new field to the search fields.
     $this->drupalPostForm(NULL, ['style_options[search_fields][' . $this->fieldName . ']' => $this->fieldName], t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     $view = Views::getView('test_display_entity_reference');
     $view->setDisplay('entity_reference_1');
     // Add the required settings to test a search operation.
     $options = ['match' => '1', 'match_operator' => 'CONTAINS', 'limit' => 0, 'ids' => NULL];
     $view->display_handler->setOption('entity_reference_options', $options);
     $this->executeView($view);
     // Test that we have searched in both fields.
     $this->assertEqual(count($view->result), 2, 'Search returned two rows');
 }
开发者ID:Wylbur,项目名称:gj,代码行数:24,代码来源:DisplayEntityReferenceTest.php

示例3: testEntityReferenceDisplay

 /**
  * Tests the entity reference display plugin.
  */
 public function testEntityReferenceDisplay()
 {
     // Add the new field to the fields.
     $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/field', ['name[entity_test__' . $this->fieldName . '.' . $this->fieldName . ']' => TRUE], t('Add and configure fields'));
     $this->drupalPostForm(NULL, [], t('Apply'));
     // Test that the right fields are shown on the display settings form.
     $this->drupalGet('admin/structure/views/nojs/display/test_display_entity_reference/entity_reference_1/style_options');
     $this->assertText('Test entity: Name');
     $this->assertText('Test entity: ' . $this->field->label());
     // Add the new field to the search fields.
     $this->drupalPostForm(NULL, ['style_options[search_fields][' . $this->fieldName . ']' => $this->fieldName], t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     $view = Views::getView('test_display_entity_reference');
     $view->setDisplay('entity_reference_1');
     // Add the required settings to test a search operation.
     $options = ['match' => '1', 'match_operator' => 'CONTAINS', 'limit' => 0, 'ids' => NULL];
     $view->display_handler->setOption('entity_reference_options', $options);
     $this->executeView($view);
     // Test that we have searched in both fields.
     $this->assertEqual(count($view->result), 2, 'Search returned two rows');
     $view->destroy();
     // Add a relationship and a field using that relationship.
     $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/relationship', ['name[entity_test.user_id]' => TRUE], t('Add and configure relationships'));
     $this->drupalPostForm(NULL, [], t('Apply'));
     $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/field', ['name[users_field_data.uid]' => TRUE], t('Add and configure fields'));
     $this->drupalPostForm(NULL, [], t('Apply'));
     // Add the new field to the search fields.
     $this->drupalPostForm('admin/structure/views/nojs/display/test_display_entity_reference/entity_reference_1/style_options', ['style_options[search_fields][uid]' => 'uid'], t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     // Test that the search still works with the ralated field.
     $view = Views::getView('test_display_entity_reference');
     $view->setDisplay('entity_reference_1');
     // Add the required settings to test a search operation.
     $options = ['match' => '2', 'match_operator' => 'CONTAINS', 'limit' => 0, 'ids' => NULL];
     $view->display_handler->setOption('entity_reference_options', $options);
     $this->executeView($view);
     // Run validation when using a relationship to the same base table.
     $this->assertEqual(count($view->result), 2, 'Search returned two rows');
     $view->destroy();
     $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/relationship', ['name[entity_test__field_test_entity_ref_entity_ref.field_test_entity_ref_entity_ref]' => TRUE], t('Add and configure relationships'));
     $this->drupalPostForm(NULL, [], t('Apply'));
     $this->drupalPostForm(NULL, [], t('Save'));
     // Test that the search still works with the related field.
     $view = Views::getView('test_display_entity_reference');
     $view->setDisplay('entity_reference_1');
     // Add IDs to trigger validation.
     $options = ['match' => '1', 'match_operator' => 'CONTAINS', 'limit' => 0, 'ids' => [1, 2]];
     $view->display_handler->setOption('entity_reference_options', $options);
     $this->executeView($view);
     $this->assertEqual(count($view->result), 2, 'Search returned two rows');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:54,代码来源:DisplayEntityReferenceTest.php


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