Skip to content

Commit

Permalink
fixes after @samdark review
Browse files Browse the repository at this point in the history
  • Loading branch information
dynasource committed Dec 1, 2016
1 parent 7f537d6 commit 9218adc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
28 changes: 8 additions & 20 deletions framework/widgets/Pjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ class Pjax extends Widget
*/
public $clientOptions;
/**
* @var string the prefix to the automatically generated pjax widget IDs.
* @see getId()
* @inheritdoc
* Note: This variable must be redeclared to force separate counting for Pjax widgets (issue #12969)
*/
public static $counter = 0;
/**
* @inheritdoc
*/
public static $pjaxAutoIdPrefix = 'w_pjax_';
public static $autoIdPrefix = 'p';


/**
* @inheritdoc
Expand Down Expand Up @@ -136,23 +141,6 @@ public function init()
}
}

/**
* Custom ID generation for Pjax widgets
* This override is to attain a more reliable match between ID's of local and remote Pjax widgets (#12969)
* The implementation follows the solution proposed in the following comment:
* @link https://github.com/yiisoft/yii2/pull/12977#issuecomment-260123078
* @since 2.0.11
*/
private static $pjaxCounter = 0;
private $_pjaxId;
public function getId($autoGenerate = true)
{
if ($autoGenerate && $this->_pjaxId === null) {
$this->_pjaxId = static::$pjaxAutoIdPrefix . static::$pjaxCounter++;
}
return $this->_pjaxId;
}

/**
* @inheritdoc
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/widgets/PjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testGeneratedIdByPjaxWidget()

$this->assertEquals('w0', $nonPjaxWidget1->options['id']);
$this->assertEquals('w1', $nonPjaxWidget2->options['id']);
$this->assertEquals('w_pjax_0', $pjax1->options['id']);
$this->assertEquals('w_pjax_1', $pjax2->options['id']);
$this->assertEquals('p0', $pjax1->options['id']);
$this->assertEquals('p1', $pjax2->options['id']);
}

protected function setUp()
Expand Down

0 comments on commit 9218adc

Please sign in to comment.