Issue Details (XML | Word | Printable)

Key: ZF-3069
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Matthew Weier O'Phinney
Reporter: Rubén Moraleda
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Cannot remove a decorator based on another decorator (with solution)

Created: 08/Apr/08 08:27 AM   Updated: 05/May/08 11:44 AM   Resolved: 05/May/08 08:42 AM
Component/s: Zend_Form
Affects Version/s: 1.5.0RC1, 1.5.0RC2, 1.5.0RC3, 1.5.0, 1.5.0PL1, 1.5.1
Fix Version/s: 1.5.2

Time Tracking:
Original Estimate: 30 minutes
Original Estimate - 30 minutes
Remaining Estimate: 30 minutes
Remaining Estimate - 30 minutes
Time Spent: Not Specified
Time Spent - Not Specified

Fix Version Priority: Must Have


 Description  « Hide

This example shows the problem.

$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.


Rubén Moraleda added a comment - 08/Apr/08 08:39 AM

My proposed 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) {
        unset($this->_decorators[$name]);
        return true;
    }

    return false;
}

At Zend/Form/Element.php


Rubén Moraleda added a comment - 08/Apr/08 09:40 AM

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.


Rubén Moraleda added a comment - 08/Apr/08 09:44 AM

2nd try.

Replace 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 the key name.


Wil Sinclair added a comment - 18/Apr/08 01:16 PM

Please evaluate and categorize as necessary.


Matthew Weier O'Phinney added a comment - 22/Apr/08 12:13 PM

Scheduling for next mini release.


Matthew Weier O'Phinney added a comment - 05/May/08 08:42 AM

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.