Problem/Motivation
We shouldn’t be overwriting the $langcode variable that’s being passed to the hook. This can cause some unpredictable behavior when we put links inside nested entities. For example: A link inside a field collection inside a node.
link.module (line 420)
function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &$optional_field_found, &$errors) {
// . . .
// We should remove this line below
$langcode = !empty($entity) ? field_language($instance['entity_type'], $entity, $instance['field_name']) : LANGUAGE_NONE;
if (!link_validate_url(trim($item['url']), $langcode)) {
Refer to the core text.module (line 118).
This function doesn't overwrite the $langcode variable. We shouldn't either.
function text_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
// @todo Length is counted separately for summary and value, so the maximum
// length can be exceeded very easily.
foreach (array('value', 'summary') as $column) {
if (!empty($item[$column])) {
if (!empty($field['settings']['max_length']) && drupal_strlen($item[$column]) > $field['settings']['max_length']) {
switch ($column) {
case 'value':
$message = t('%name: the text may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length']));
break;
case 'summary':
$message = t('%name: the summary may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length']));
break;
}
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => "text_{$column}_length",
'message' => $message,
);
}
}
}
}
}
This code was introduced in this issue.
https://www.drupal.org/node/2247261
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | link-field_link_validate_overrites_langcode-2632728.patch | 1.09 KB | partdigital |
Comments
Comment #2
partdigital commentedComment #3
partdigital commentedComment #4
partdigital commentedComment #5
partdigital commentedComment #6
partdigital commentedComment #7
partdigital commentedComment #8
partdigital commentedComment #9
jcfiala commentedGood point.
Comment #10
jcfiala commentedPatch applied to the 7.x-1.x branch, should show up in 24 hours or so.
Comment #11
partdigital commentedI don't know how clean your want your commit history but I noticed the commit message was wrong, it says "UPC-99: UPC-99: Apply patch: link-field_link_validate_overrites_langcode-2632728.patch' something more meaningful would be: 'Issue #2632728 by partdigital: field_link_validate overwrites $langcode variable. Is it possible to rewrite that commit?