0

I know how to remove a pattern via the UI. Is it possible to do this programmatically to be used in hook_update()?

EDIT: I think asking this answered my question. Will post a followup answer. Probably just entity_load/entity::delete

  • 1
    "EDIT: I think asking this answered my question. Will post a followup answer. Probably just entity_load/entity::delete". Yes. – Berdir Sep 27 '18 at 20:46
0

Ended up throwing the following into my_module.install

/**
 * Deletes the product_nodes path alias. Check watchdog for error in case of failure.
 */
function my_module_update_8001(){
  $alias_id = 'product_nodes';
  if($alias_entity = Drupal\pathauto\Entity\PathautoPattern::load($alias_id)){
    try{
      $alias_pattern = $alias_entity->getPattern();
      $alias_entity->delete();
      return t('Successfully deleted @id PathAuto pattern. If this was done in error, you can recreate it by using the pattern: @pattern.',
        array(
          '@id'=>$alias_id,
          '@pattern'=> $alias_pattern,
        )
      );
    } catch(Exception $e){
      \Drupal::logger('my_module')->error('Encountered the following error while trying to delete the @id path alias pattern: @error',
        array(
          '@id'=>$alias_id,
          '@error'=>$e->getMessage(),
        )
      );
      return 'Failed to delete @id PathAuto pattern. Check the error log for details.';
    }
  } else {
    return t('No PathAuto pattern found with the ID @id.',
      array(
        '@id'=>$alias_id,
      )
    );
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.