Commit ccd7318c authored by NickWilde's avatar NickWilde

Issue #2711841 by skippednote, VinayLondhe, trebormc, NickWilde: Change title...

Issue #2711841 by skippednote, VinayLondhe, trebormc, NickWilde: Change title of the Color field from Color to Field Label in HTML5 Color Picker
parent f6955d5d
......@@ -58,8 +58,10 @@ class ColorFieldWidgetHTML5 extends WidgetBase {
}
}
$label = $this->fieldDefinition->getLabel();
$description = $this->fieldDefinition->getDescription();
$element['color'] = array(
'#title' => $this->t('Color'),
'#title' => $label,
'#type' => 'color',
'#maxlength' => 7,
'#size' => 7,
......@@ -72,6 +74,7 @@ class ColorFieldWidgetHTML5 extends WidgetBase {
$element['opacity'] = array(
'#title' => $this->t('Opacity'),
'#description' => $description,
'#type' => 'number',
'#min' => 0,
'#max' => 1,
......@@ -80,6 +83,8 @@ class ColorFieldWidgetHTML5 extends WidgetBase {
'#default_value' => isset($items[$delta]->opacity) ? $items[$delta]->opacity : NULL,
'#suffix' => '</div>',
);
} else {
$element['color']['#description'] = $description;
}
return $element;
......
......@@ -7,7 +7,7 @@ use Drupal\Tests\BrowserTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the creation of telephone fields.
* Tests color field formatters.
*
* @group color_field
*/
......@@ -93,7 +93,7 @@ class ColorFieldFormatterTest extends BrowserTestBase {
$this->assertSession()->responseContains('placeholder="1.0"');
$this->assertSession()->responseContains('Freeform Color');
// Test basic entry of telephone field.
// Test basic entry of color field.
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_color[0][color]' => "#E70000",
......@@ -264,7 +264,7 @@ class ColorFieldFormatterTest extends BrowserTestBase {
])->save();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->assertSession()->responseContains('body { background-color: RGB(255,244,48); }');
$this->assertSession()->responseContains('body { background-color: RGB(255,255,255); }');
// Test with token selector.
$edit = [
......
<?php
namespace Drupal\Tests\color_field\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests color field widgets.
*
* @group color_field
*/
class ColorFieldWidgetTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'field',
'node',
'color_field',
];
/**
* The Entity Type Manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* A user with permission to create articles.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(['type' => 'article']);
$this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']);
$this->drupalLogin($this->webUser);
$this->entityTypeManager = $this->container->get('entity_type.manager');
FieldStorageConfig::create([
'field_name' => 'field_color',
'entity_type' => 'node',
'type' => 'color_field_type',
])->save();
FieldConfig::create([
'field_name' => 'field_color',
'label' => 'Freeform Color',
'description' => 'Color field description',
'entity_type' => 'node',
'bundle' => 'article',
])->save();
}
/**
* Test color_field_widget_html5.
*/
public function testColorFieldWidgetHtml5() {
/** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $form */
$form = $this->entityTypeManager->getStorage('entity_form_display')
->load('node.article.default');
$form->setComponent('field_color', [
'type' => 'color_field_widget_html5',
])->save();
/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $display */
$display = $this->entityTypeManager->getStorage('entity_view_display')
->load('node.article.default');
$display->setComponent('field_color', [
'type' => 'color_field_formatter_text',
'weight' => 1,
])->save();
// Confirm field label and description are rendered.
$this->drupalGet('node/add/article');
$this->assertSession()->fieldExists("field_color[0][color]");
$this->assertSession()->fieldExists("field_color[0][opacity]");
$this->assertSession()->responseContains('Freeform Color');
$this->assertSession()->responseContains('Color field description');
// Test basic entry of color field.
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_color[0][color]' => "#E70000",
'field_color[0][opacity]' => 1,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertSession()->responseContains('#E70000 1</div>');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment