When using title replacement, and saving a node there is a message "Could not retrieve title from feed". Title module actually hides the title form element, and adds a field replacement for it. So there is no value for the node title property on hook_node_validate, when the field replacement is properly populated.

Comments

MiroslavBanov created an issue. See original summary.

megachriz’s picture

Is there a way to detect if the title form element is available in feeds_node_validate() instead of checking if the title module is enabled?

See also this related issue: #1621602: Could not retrieve title from feed - Make title field only optional if the parser can deliver a title.
That issue is about making the title field only non-required if the selected parser can provide a title. The CSV parser cannot.

miroslavbanov’s picture

There is a way to check for form element.

Better yet check if title field is on the node:

if (field_info_instance('node', 'title_field', $node->type)) {
  if ($items = field_get_items('node', $node, 'title_field')) {
    $title = $items[0]['#value'];
  }
}

OR using title field API:

if (module_exists('title') && title_field_replacement_enabled('node', $node->type, 'title')) {
  $info = title_field_replacement_info('node', 'title');
  if ($items = field_get_items('node', $node, $info['field']['field_name'])) {
    $title = $items[0]['#value'];
  }
}
megachriz’s picture

Status: Active » Needs review
StatusFileSize
new778 bytes

It is recommended to try to avoid writing special case solutions (like checking if module x is available) in a module whenever possible. The module code could get bloated with things like "If module x is available, do this. But if module y is also available and module z is not, do this."
Instead, the attached patch checks if the default title form element is hidden. If so, it doesn't try to retrieve a title from the source and as a result no error will be triggered for this element.

  • MegaChriz committed 2cc843c on 7.x-2.x
    Issue #2645074 by MegaChriz, MiroslavBanov: Could not retrieve title...
megachriz’s picture

Status: Needs review » Fixed

Committed #4.

Status: Fixed » Closed (fixed)

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