-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/sub page aliases #46
Conversation
When reviewing ignore the failing functional js test. It seems to be an issue that potentially affects more than our repo #47 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall functionality seems to work. Thanks. I have suggested some minor improvements to the code.
localgov_elections.module
Outdated
* Returns nothing. | ||
*/ | ||
function localgov_elections_generate_election_aliases(NodeInterface $entity) { | ||
if ($entity->getEntityTypeId() == 'node' && $entity->getType() == 'localgov_election') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$entity->getEntityTypeId() == 'node'
: this is kind of redundant because we know $entity is of type NodeInterface :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true. Fixed.
localgov_elections.module
Outdated
$storage = \Drupal::entityTypeManager()->getStorage('path_alias'); | ||
$query = $storage->getQuery(); | ||
$query->condition('alias', $alias); | ||
$query->accessCheck(FALSE); | ||
$result = $query->execute(); | ||
|
||
if ($result) { | ||
$result = reset($result); | ||
$result = $storage->load($result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like this:
$alias_entities = $storage->loadByProperties(['alias' => $alias]);
if ($alias_entities) {
try {
current($alias_entites)->delete();
}
...
}
or even
$alias_entities = $storage->loadByProperties(['alias' => $alias]);
array_walk($alias_entities, fn(Drupal\path_alias\PathAliasInterface $alias_entity) => $alias_entity->delete())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the first suggestion but added a guard to deal with current
. If that array was empty, that method might not exist.
localgov_elections.module
Outdated
* @return void | ||
* Returns nothing. | ||
*/ | ||
function localgov_elections_delete_election_aliases($election) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the absence of doc comment for the $election
parameter, it would be good to have a type declaration e.g. NodeInterface $election
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. Added in.
@Adnan-cds Addressed the points you raised I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. Thanks a lot :)
Should close #29.