Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • 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
  • Component/s: Zend_Form
  • Labels:
    None
  • Fix Version Priority:
    Must Have

Description

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.

Activity

Hide
Rubén Moraleda added a comment -

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

Show
Rubén Moraleda added a comment - 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
Hide
Rubén Moraleda added a comment -

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.

Show
Rubén Moraleda added a comment - 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.
Hide
Rubén Moraleda added a comment -

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.

Show
Rubén Moraleda added a comment - 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.
Hide
Wil Sinclair added a comment -

Please evaluate and categorize as necessary.

Show
Wil Sinclair added a comment - Please evaluate and categorize as necessary.
Hide
Matthew Weier O'Phinney added a comment -

Scheduling for next mini release.

Show
Matthew Weier O'Phinney added a comment - Scheduling for next mini release.
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
30m
Original Estimate - 30 minutes
Remaining:
30m
Remaining Estimate - 30 minutes
Logged:
Not Specified
Time Spent - Not Specified