Issues

ZF-10459: Zend_Navigation_Container->removePage() should have option to remove page recursively

Description

Comments

I don't understand your problem. Can you give an example?


// Navigation
$container = new Zend_Navigation(array(
    array(
        'label' => 'Home',
        'uri'   => 'home',
    ),
    array(
        'label' => 'Products',
        'uri'   => 'products',
        'pages' => array(
            array(
                'label' => 'DVD',
                'uri'   => 'dvd',
            ),
            array(
                'label' => 'Games',
                'uri'   => 'games',
            ),
            array(
                'label' => 'Music',
                'uri'   => 'music',
            ),
        ),
    ),
    array(
        'label' => 'Contact',
        'uri'   => 'contact',
    ),
    array(
        'label' => 'imprint',
        'uri'   => 'imprint',
    ),
));

// View
$view = new Zend_View();

echo '

Output 1:

'; echo $view->navigation($container)->menu(); // Remove page "Products" $container->removePage(1); echo '

Output 2:

'; echo $view->navigation($container)->menu();

Output 1:

Home Products DVD Games Music Contact imprint

Output 2:

Home Contact imprint

Hi Jiri, Any comments on this?

Hi Kai,

my problem is that it is not possible to remove pages in subcontainers. Eg. page DVD cant be deleted by calling something like $container->removePageByUri(dvd, true); Where "true" means Search all containers recursively. You have to get the right container first and then delete your page.

I think that it would be nice to have a function which searches all containers recursively for page given to delete.

Ah, I understand.

|findOneBy|removeOneBy| |findAllBy|removeAllBy| |findBy|removeBy|

I think for the implementation, we can use all "find" methods.


public function removeOneBy($property, $value)
{
    $page = $this->findOneBy($property, $value);
    
    if (null !== $page) {
        return $this->removePage($page);
    }
    
    return false;
}

public function removeAllBy($property, $value)
{
    $pages = $this->findAllBy($property, $value);
    
    if (false !== empty($pages)) {
        foreach ($pages as $page) {
            $this->removePage($page);
        }
        
        return true
    }
    
    return false;
}

public function removeBy($property, $value, $all = false)
{
    if ($all) {
        return $this->removeAllBy($property, $value);
    } else {
        return $this->removeOneBy($property, $value);
    }
}

I will write some unit test.

Thanks for your fast feedback!

Based on the new filter options ({{useRegex}}). See ZF-9994