The title is not passed to hook_field_diff_view if the "No title" option is chosen in the field settings and a php warning is raised.
Patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

krystalcode’s picture

sumitmadan’s picture

Status: Active » Postponed (maintainer needs more info)

I am not able to reproduce the issue. Can you please provide more information on this (which version of diff you are using etc.)?

rrrob’s picture

Confirmed patch in #1 resolves this error.

Using diff version 7.x-3.2

rrrob’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community
sumitmadan’s picture

Still I am not getting the error. Please let me know how and where I can see the error?

Argus’s picture

I cannot reproduce this on a regular Drupal install, but I can reproduce it on an Open Atrium installation.

Note that Open Atrium has a submodule oa_diff that allows a specific revision to be indicated. Perhaps this is causing the error?

Created an issue in the OA issue queue that links to this one. #2748703: Setting Link title to "no title" produces a PHP Notice

krystalcode’s picture

I was working with a normal Drupal installation when I filed this bug - it's been long time and I don't have the code so I can't provide more details at the moment. It's most likely related to PHP version though.

$diff_items[$delta] = $item['title'] . $item['url'];

It tries to render $item['title'] while it doesn't exist, and certain versions of PHP may raise warnings. The patch sets this value to an empty string, if it is not already set. It is straight forward and it won't introduce any regression, so I would suggest that it is merged.

dqd’s picture

Priority: Normal » Minor
Status: Reviewed & tested by the community » Needs work

@krystalcode: while I would agree we still need input here. Setting it to an empty string can cause problems on other spots inside the diff functionality part (not sure) where it is required that it doesn't exist if not set. Title is an option and therefore we maybe should rather use an if isset, take it in, if not, than do-whatever without it than setting it to an empty existing string. Especially in user interaction it can confuse to see an empty title somewhere even if title is not set by content admin.

I've tried another way to wrap isset() around before the main action, but with no luck (WSOD on diff page). Diff still requires both fields which link supports, even if not set.


function link_field_diff_view($items, $context) {
  $diff_items = array();
  foreach ($items as $delta => $item) {
    // checks if var $item['title'] is set (exist)
    if (isset($item['title'])) {
      // checks if $item['url'] and $item['title'] are not NULL
      // @TODO wouldn't NOT EMPTY be better here ?
      if ($item['url'] && $item['title']) {
        $diff_items[$delta] = $item['title'] . ' (' . $item['url'] . ')';
      }
      else {
        $diff_items[$delta] = $item['title'] . $item['url'];
      }
    else
      // since we already know that $item['title'] does not exist
      // we don't need any of the above concatenating in this iteration step
      // @TODO - but this seems NOT to work (WSOD) sadly!
     $diff_items[$delta] = $item['url'];
  }
  return $diff_items;
}

  1. I am not sure if this isn't rather a conceptual issue to discuss in the Diff issue queue how it handles "disabled" but defacto in DB existing fields?
  2. And by the way: a PHP notice is not really a bug. PHP notices should be avoided, yes, but they are not errors and they come and go, even with core. So I'll set it to minor.

That was the last minor time I had today to spend for this, sorry ... thoughts ?

krystalcode’s picture

Hi @diqidoq,

I originally resorted to setting it to empty string in order to keep the code cleaner by avoiding nested statements. I understand the concern and I would be happy with either approach.

However notice that the arguments are not passed by reference and setting the $item['title'] to empty string here won't affect other parts of the program. The function is short and it is simply preparing a string and returning it, so there is little chance of confusion. In that context, I would personally vote for readability over semantics, but I'd be happy with your approach as well.

Yeah agreed, this is of minor priority - although it is a warning and not notice and I would still consider it a bug.

naidim’s picture

To Duplicate the error: Install Link, Diff modules. Create a Content Type that has a Link field without a Title. Create then Edit a node of that Content Type. Click "View Changes" button.

Notice: Undefined index: title in link_field_diff_view() (line 14 of /sites/uvm/content/sites/all/modules/contrib/link/link.diff.inc).
Notice: Undefined index: title in link_field_diff_view() (line 18 of /sites/uvm/content/sites/all/modules/contrib/link/link.diff.inc).

What I believe is the issue: link.diff.inc line 14 just checks $item['title'] without checking if it exists (undefined index) and line 18 tries to concatenate $item['title'] even if it is not set or doesn't have a value.

Fix: Instead of setting it to empty string if not set, just check if isset, and don't concatenate non-existing/empty title.

line 14: if ($item['url'] && isset($item['title'])) {
line 18: $diff_items[$delta] = $item['url'];

naidim’s picture

Patch with previously mentioned code changes. Tested with Title links and no title links and appears to work as intended.

jbitdrop’s picture

@crystalcode @diqidoq @naidim Thanks for all the input on this issue. Helped a lot to tackle down the issue. Will review the latest patch asap.

renatog’s picture

Status: Needs work » Reviewed & tested by the community

Hi guys.

Thank you very for contributions.

I applied the patch #11 and works good for me.

Regards.

  • RenatoG committed af6d13a on 7.x-1.x authored by krystalcode
    Issue #2480723 by krystalcode, naidim, rrrob, sumitmadan, Argus, diqidoq...
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Fixed.

Committed to the dev branch.

Thank you very much.

Regards.

Status: Fixed » Closed (fixed)

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