Skip to content
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

Merged
merged 3 commits into from
Jun 27, 2024
Merged

Feature/sub page aliases #46

merged 3 commits into from
Jun 27, 2024

Conversation

chriswales95
Copy link
Member

Should close #29.

@chriswales95
Copy link
Member Author

When reviewing ignore the failing functional js test. It seems to be an issue that potentially affects more than our repo #47

Copy link
Contributor

@Adnan-cds Adnan-cds left a 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.

* Returns nothing.
*/
function localgov_elections_generate_election_aliases(NodeInterface $entity) {
if ($entity->getEntityTypeId() == 'node' && $entity->getType() == 'localgov_election') {
Copy link
Contributor

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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true. Fixed.

Comment on lines 201 to 209
$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);
Copy link
Contributor

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())

Copy link
Member Author

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.

* @return void
* Returns nothing.
*/
function localgov_elections_delete_election_aliases($election) {
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Added in.

localgov_elections.module Show resolved Hide resolved
localgov_elections.module Show resolved Hide resolved
@chriswales95
Copy link
Member Author

@Adnan-cds Addressed the points you raised I think.

Copy link
Contributor

@Adnan-cds Adnan-cds left a 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 :)

@markconroy markconroy removed their request for review June 26, 2024 16:25
@chriswales95 chriswales95 merged commit 3054894 into 1.x Jun 27, 2024
5 of 8 checks passed
@chriswales95 chriswales95 deleted the feature/sub-page-aliases branch June 27, 2024 08:41
@chriswales95 chriswales95 mentioned this pull request Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Automate URL alias for subpages
2 participants