Issues

ZF-3069: Cannot remove a decorator based on another decorator (with solution)

Issue Type: Bug Created: 2008-04-08T08:27:45.000+0000 Last Updated: 2008-05-05T11:44:41.000+0000 Status: Resolved Fix version(s): - 1.5.2 (15/May/08)

Reporter: Rubén Moraleda (xplorastudios) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:

Description

This example shows the problem.

<pre class="highlight">

$form=new Zend_Form;
        
$form->addElement(
    'text',
    'mytextfield',
    array(
        'label' => 'My Textfield',
    )
);

$element=$form->getElement('mytextfield');

$element->addDecorator(array('MyDecorator'=>'HtmlTag'), array( 'tag' => 'dl', 'separator'=>PHP_EOL));

print_r(array_keys($element->getDecorators()); // Display element decorators

$element->removeDecorator('MyDecorator'); // Remove MyDecorator

print_r(array_keys($element->getDecorators()); // MyDecorator hasn't been removed, HtmlTag decorator has been removed instead.

Comments

Posted by Rubén Moraleda (xplorastudios) on 2008-04-08T08:39:19.000+0000

My proposed solution:

Swap this:

<pre class="highlight">
/**
 * Remove a single decorator
 *
 * @param  string $name
 * @return bool
 */
public function removeDecorator($name)
{
    $decorator = $this->getDecorator($name);
    if ($decorator) {
        $name = get_class($decorator);
        unset($this->_decorators[$name]);
        return true;
    }

    return false;
}

For this:

<pre class="highlight">
/**
 * Remove a single decorator
 *
 * @param  string $name
 * @return bool
 */
public function removeDecorator($name)
{
    $decorator = $this->getDecorator($name);
    if ($decorator) {
        unset($this->_decorators[$name]);
        return true;
    }

    return false;
}

At Zend/Form/Element.php

Posted by Rubén Moraleda (xplorastudios) on 2008-04-08T09:40:14.000+0000

There was an error in my previous proposed solution. Here is the correct solution:

Swap this:

/** * Remove a single decorator * * @param string $name * @return bool */ public function removeDecorator($name) { $decorator = $this->getDecorator($name); if ($decorator) { $name = get_class($decorator); unset($this->_decorators[$name]); return true; }

return false;

}

For this:

/** * Remove a single decorator * * @param string $name * @return bool */ public function removeDecorator($name) { $decorator = $this->getDecorator($name); if ($decorator) { if ( !isset( $this->_decorators[$name] ) ) $name = get_class($decorator); unset($this->_decorators[$name]); return true; }

return false;

}

At Zend/Form/Element.php

The decorator will be deleted using his class name only if is not found by key name.

Posted by Rubén Moraleda (xplorastudios) on 2008-04-08T09:44:17.000+0000

2nd try.

Replace this:

<pre class="highlight">
/**
 * Remove a single decorator
 *
 * @param  string $name
 * @return bool
 */
public function removeDecorator($name)
{
    $decorator = $this->getDecorator($name);
    if ($decorator) {
        $name = get_class($decorator);
        unset($this->_decorators[$name]);
        return true;
    }

    return false;
}

For this:

<pre class="highlight">
/**
 * Remove a single decorator
 *
 * @param  string $name
 * @return bool
 */
public function removeDecorator($name)
{
    $decorator = $this->getDecorator($name);
    if ($decorator) {
        if ( !isset( $this->_decorators[$name] ) ) $name = get_class($decorator);
        unset($this->_decorators[$name]);
        return true;
    }

    return false;
}

At Zend/Form/Element.php

The decorator will be deleted using his class name only if is not found by the key name.

Posted by Wil Sinclair (wil) on 2008-04-18T13:16:14.000+0000

Please evaluate and categorize as necessary.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T12:13:34.000+0000

Scheduling for next mini release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-05-05T08:42:43.000+0000

Fixed in trunk and 1.5 release branch as of r9365; applied fixes to form, element, and display group classes, as the issue was present in each.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts