Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel’s picture

swentel’s picture

Status: Postponed » Active
aspilicious’s picture

I see this in the sandbox commit, this ok?

+          'length' => 254,
+          'not null' => 2048,
swentel’s picture

Nah, was wrong, have that ok locally already

mordonez’s picture

Hi,

I updated the patch with the same format as Telephone field (namespace corrections and annotations).

mordonez’s picture

Sorry I missed to add new and deleted files

mordonez’s picture

Sorry I missed to add the new and deleted files

aspilicious’s picture

Status: Active » Needs review
yched’s picture

Status: Needs review » Needs work

Thanks @mordonez !

+++ b/core/modules/link/lib/Drupal/link/Plugin/field/field_type/LinkItem.phpundefined
@@ -0,0 +1,127 @@
+      '#default_value' => isset($this->instance->settings['title']) ? $this->instance->settings['title'] : DRUPAL_OPTIONAL,

the instance should be accessed through $this->getInstance().
No need for the isset() check, it should always be set (I know this comes from the existing code, but let's clean this while we're here)

+++ b/core/modules/link/lib/Drupal/link/Plugin/field/field_type/LinkItem.phpundefined
@@ -0,0 +1,127 @@
+    $item = $this->getValue();
+    // Trim any spaces around the URL and link text.
+    $this->set('url', trim($item['url']));
+    $this->set('title', trim($item['title']));
+  }

Let's avoid going through getValue().
This can be:
$this->url = trim($this->url);
$this->title = trim($this->title);

mordonez’s picture

Status: Needs work » Needs review
FileSize
7.5 KB

Thanks @yched.

here the corrections.

yched’s picture

Status: Needs review » Needs work

thanks @mordonez!

hint: it's a good practice, when you post a new version of a patch, to also post an "interdiff" - a .txt file showing the diff between the previous and the new version. It helps reviews tremendously :-)
See https://drupal.org/documentation/git/interdiff (if you're on linux, the interdiff command line provided by the patchutils package is really handy).

Last nitpick - my bad, I should have spotted that earlier:
The goal is to make our FieldItem classes (like LinkItem here) be usable for configurable fields (that can be added through the UI) as well as base entity fields (that are hardcoded in the Entity definition).
This means relying as little as possible on the Field / FieldInstance definition structures that are specific to configurable fields, and instead use the FieldDefinitionInterface.

In this case, this will be as simple as replacing this line:
'#default_value' => $this->getInstance()->settings['title'],
by
'#default_value' => $this->getFieldDefinition()->getFieldSetting('title'),
:-)

mordonez’s picture

thanks for the interdiff's advice

here the patch that uses the FieldDefinitionInterface

mordonez’s picture

Status: Needs work » Needs review
yched’s picture

Status: Needs review » Reviewed & tested by the community

Thanks !

yched’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed a7dbbd5 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.