\Drupal\views_ui\ViewListBuilder
class ViewListBuilder extends ConfigEntityListBuilder {
// ...
/**
* {@inheritdoc}
*/
protected $limit;
// ...
public function __construct( ... ) {
// ...
$this->limit = FALSE;
}
// ...
}
The $limit
variable is a property defined on the parent EntityListBuilder class and is inherited by ViewListBuilder. There is no need to redefine the variable in this subclass. Note that $limit
is only used from within the code of the parent classes - there is no other usage of $limit
inside ViewListBuilder.
I confess I can't think of a situation (in PHP) where this would cause an error in execution, but I feel this obscures what is going on in the code. I think it would make the code clearer if the override were removed.
This is also the case in
core/modules/block/src/BlockListBuilder.php
core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php
which we should also clean up while we are at it.
Comment | File | Size | Author |
---|---|---|---|
#14 | 3033986-14-useless-property-override.patch | 1.94 KB | TR |
useless-override.patch | 560 bytes | TR | |
Comments
Comment #2
TR CreditAttribution: TR commentedComment #5
rishabhthakur CreditAttribution: rishabhthakur at Srijan | A Material+ Company for Drupal India Association commentedComment #6
rishabhthakur CreditAttribution: rishabhthakur at Srijan | A Material+ Company for Drupal India Association commentedUpdated patch to fix Notice error with protected variable
Comment #8
KapilV CreditAttribution: KapilV as a volunteer and at OpenSense Labs commentedprotected $limit; Variable using for testing of multiple views.
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\views\Entity\View;
use Drupal\views\Views;
/**
* Tests the views list.
*
* @group views_ui
*/
class ViewsListTest extends UITestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['block', 'views_ui'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A user with permission to administer views.
*
* @var \Drupal\user\Entity\User
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('local_actions_block');
$this->adminUser = $this->drupalCreateUser(['administer views']);
$this->drupalLogin($this->adminUser);
}
/**
* Tests that the views list does not use a pager.
*/
public function testViewsListLimit() {
// Check if we can access the main views admin page.
$this->drupalGet('admin/structure/views');
$this->assertResponse(200);
$this->assertLink(t('Add view'));
// Count default views to be subtracted from the limit.
$views = count(Views::getEnabledViews());
// Create multiples views.
$limit = 51;
$values = $this->config('views.view.test_view_storage')->get();
for ($i = 1; $i <= $limit - $views; $i++) {
$values['id'] = 'test_view_storage_new' . $i;
unset($values['uuid']);
$created = View::create($values);
$created->save();
}
$this->drupalGet('admin/structure/views');
// Check that all the rows are listed.
$this->assertEqual(count($this->xpath('//tbody/tr[contains(@class,"views-ui-list-enabled")]')), $limit);
}
}
It's not Useless property.
Comment #9
TR CreditAttribution: TR commented@rishabhthakur: Why did you remove that line of code? Your patch is clearly wrong and fails the core test.
@kapilkumar0324: Please don't post large blocks of unformatted code in the issue queue. It's hard to read and confuses the issue.
No one said it's a useless property. My original post says it's a useless property OVERRIDE. The property is still needed and still exists in my original patch.
Both of you have totally misunderstood the original issue. I have triggered a re-test of that original patch and as you can see the patch still works with no test failures and no coding standards violations.
This issue is about elementary object-oriented programming. We have this situation:
class B inherits the definition of $limit, it does not need to redeclare and override the $limit property. It's that simple.
Comment #10
dwwAgree with @TR here. Original patch https://www.drupal.org/files/issues/2019-02-18/useless-override.patch is RTBC. Confirmed that
projected $limit
lives incore/lib/Drupal/Core/Entity/EntityListBuilder.php
, the grandparent of this class, so we don't need our own override of it.Removing 'Novice' tag since apparently novices don't necessarily understand object oriented coding and inheritance, nor read issue summaries carefully. ;)
Cheers,
-Derek
Comment #11
rishabhthakur CreditAttribution: rishabhthakur at Srijan | A Material+ Company for Drupal India Association commentedHi TR,
You're right. Sorry for the confusion :)
its clearly mention on title "Useless property override in ViewListBuilder"
Comment #12
KapilV CreditAttribution: KapilV as a volunteer and at OpenSense Labs commentedHi TR,
Sorry for the misunderstanding. You are right.
Comment #13
jungleDoubt that this is not the only one in core. There are more to clean up. Needs follow-up or enlarge the scope?
Comment #14
TR CreditAttribution: TR commentedI found that 3 out of the 38 core list builders have this problem. These are:
I'm fine with expanding this issue as long as we restrict the scope to just this one
$limit
property for classes that extend from the coreEntityListBuilder
, and don't try to find or solve all other useless property overrides in core. Here's a new patch.Comment #15
LendudeDoing all overrides of $limit sounds good as a scope I think. Re-checked that these are the only occurrences in core and they are (there are more in contrib).
Updated to task since this is not a bug, updated the title and IS to match the new direction.
Leaving RTBC cause the new patch looks good and it is nice that core now does the override of the pager setting in a consistent way.
Comment #16
Lendudereally updated the title this time...
Comment #17
dwwEven more specific/accurate title. ;)
RTBC +1
Thanks!
-Derek
Comment #19
catchCommitted 3bcb729 and pushed to 9.1.x. Thanks!