If there is no menu setting in node type I get next message on node add/edit form:

Notice: Undefined index: menu in menu_target_edit_form_extra_elements() (line 38 of

/srv/default/vcs/web/sites/all/modules/contrib/menu_target/menu_target.admin.inc).

Comments

a.milkovsky created an issue. See original summary.

a.milkovsky’s picture

Assigned: a.milkovsky » Unassigned
Status: Active » Needs review
StatusFileSize
new877 bytes
fago’s picture

Status: Needs review » Needs work
+++ b/menu_target.admin.inc
@@ -35,7 +35,15 @@ function menu_target_edit_form_extra_elements(&$form, $node_form) {
+      elseif(!empty($form['options']['#value'])) {

this has a different logic than before. previously it was used if !$node_form

a.milkovsky’s picture

Status: Needs work » Needs review
StatusFileSize
new871 bytes

thanks, you are absolutely right.

fago’s picture

Status: Needs review » Needs work
+++ b/menu_target.admin.inc
@@ -35,7 +35,15 @@ function menu_target_edit_form_extra_elements(&$form, $node_form) {
+    elseif(!empty($form['options']['#value'])) {

missing space after if

a.milkovsky’s picture

Status: Needs work » Needs review
StatusFileSize
new872 bytes

:-)

fago’s picture

Status: Needs review » Reviewed & tested by the community

and finally...!

stevendeleus’s picture

I think there's a better solution. Now the checkbox 'Open in a new window' appears on a node form even if no menus are selected. This is because $enabled_menus is never empty:

<?php
function menu_target_edit_form_extra_elements(&$form, $node_form) {

  if ($node_form) {
    $type = $form['#node']->type;
    $enabled_menus = variable_get('menu_options_' . $type, array('main-menu' => 'main-menu'));
    if (empty($enabled_menus)) {
      return;
    }

?>

This is also causing the aforementioned notice. Instead I propose the following:

<?php
function menu_target_edit_form_extra_elements(&$form, $node_form) {

  if ($node_form) {
    $type = $form['#node']->type;
    $enabled_menus = variable_get('menu_options_' . $type, array('main-menu' => 'main-menu'));
    $enabled_menu = FALSE;
    foreach($enabled_menus as $enabled) {
      if($enabled) { 
        $enabled_menu = TRUE;
        break;
      }
    }
    if(!$enabled_menu) {
      return;
    }

?>
oostie’s picture

Does anyone still get this error?

The variable menu_options_NODE_TYPE is always created by Drupal core even when no menu is checked in the content type settings.
To prevent this error it's even better to change

variable_get('menu_options_' . $type, array('main-menu' => 'main-menu'));

to

variable_get('menu_options_' . $type, FALSE);

In that case $enabled_menus is empty when the variable does not exist.

oostie’s picture

Status: Reviewed & tested by the community » Needs review
stevendeleus’s picture

In that case the issue will persist if the variable exists, but none of the menus are selected for the node type. The variable will return

<?php
array('main-menu' => 0)
?>

if you deselect the default option. In other words, the check should be on non-zero values.

stevendeleus’s picture

I have another solution: replace
if (empty($enabled_menus)) {
with
if (empty($enabled_menus) || count(array_filter($enabled_menus)) == 0) {

richgerdes’s picture

StatusFileSize
new580 bytes

The last patch (6) for this, no longer applies to do update in #2320615. The proposed solution better handles the return case, by checking for only non zero values. The attached patch should resolve this based on the thread. I additionally updated

 variable_get('menu_options_' . $type, array('main-menu' => 'main-menu')); 

to

variable_get('menu_options_' . $type); 

to use the default value NULL not FALSE since this provides the same result from empty().

Status: Needs review » Needs work

The last submitted patch, 13: menu_target-empty_options-2553757-12.patch, failed testing.

daniel korte’s picture

Status: Needs work » Needs review
StatusFileSize
new636 bytes

#13 results in a PHP error:
Fatal error: Can't use function return value in write context in menu_target/menu_target.admin.inc on line 19
This is because the result of array_filter() is sent directly to empty().

richgerdes’s picture

Status: Needs review » Reviewed & tested by the community

The patch looks good, marking as RTBC.

  • Oostie committed 5adf2e4 on 7.x-1.x authored by Daniel Korte
    Issue #2553757 by a.milkovsky, richgerdes, Daniel Korte, fago,...
oostie’s picture

Committed and created a new version, thnx!

oostie’s picture

Status: Reviewed & tested by the community » Fixed

catapipper’s picture

Status: Fixed » Needs review
Related issues: +#2937755: Version 1.7 doesn't work for me.

I believe the wrong patch was committed resulting in version 1.7 having a fatal error on install.

Looks like #13 was committed not #15 which does work.

ramzypro’s picture

Can confirm - most recent version causes fatal error when visiting update.php after installing, had to roll back to previous version.

garrettw’s picture

@Oostie Can this be fixed with #15 and released?