Provide new coders for Facet API Pretty Paths. Coder for dates without time and Coder for taxonomy without ID.
Check adapter url processor. Add new facet settings only for "pretty_paths" url processor.
Extended options: Add options select pretty path coder. Options for date coder.

Coder for dates better use with Facet API Date Popup Calendar (https://drupal.org/sandbox/uzlov/2160651).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

uzlov’s picture

dasjo’s picture

Hi,

Thanks a lot for your contribution! I'm on my mobile phone right now so can't really do an in-depth review atm.

The first question that I have though is, why would we need another taxonomy no-id coder? That should already be covered by the pathauto coder.

Regards

uzlov’s picture

Issue summary: View changes
uzlov’s picture

"Taxonomy no id" coder it's a little bit other coder than pathauto coder. This is coder used "term name" for parh alias, when this name unique in current vocabulary.

andypost’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review

We using this modules in production so glad to see this bunch of fixes shipped with the module

dasjo’s picture

i'm not yet convinced of introducing the "taxonomy no id" as it does almost the same as the pathauto coder.

maybe we should merge those into a single one with a setting on which strategy to choose from: a) just use the term name, b) use pathpauto if available.

note that there is also some work going on in #1981578: Allow to remove "Taxonomy Vocabulary" from urls.

besides my conceptual concerns, here's a quick code review:

  1. +++ b/facetapi_pretty_paths.module
    @@ -47,60 +47,129 @@ function facetapi_pretty_paths_form_facetapi_facet_display_form_alter(&$form, &$
    +    // Load all coders for <strong>oprion</strong> list.
    

    typo

  2. +++ b/facetapi_pretty_paths.module
    @@ -47,60 +47,129 @@ function facetapi_pretty_paths_form_facetapi_facet_display_form_alter(&$form, &$
    +    $default_<strong>sected</strong>_coder = 'default';
    

    typo

  3. +++ b/plugins/coders/facetapi_pretty_paths_coder_taxonomy_no_id.inc
    @@ -0,0 +1,73 @@
    +    if (count($exploded) == 1) {
    +
    +      $facet_settings = $args['adapter']->getFacetSettingsGlobal($args['facet']);
    +      $vocabulary = !empty($facet_settings->settings['pretty_paths_taxonomy_no_id_vocabulary']) ? $facet_settings->settings['pretty_paths_taxonomy_no_id_vocabulary'] : NULL;
    +
    +      $terms = taxonomy_get_term_by_name($exploded[0], $vocabulary);
    +      $term = reset($terms);
    +      if (is_object($term)) {
    +        $args['value'] = $term->tid;
    +      }
    +      else {
    +        $args['value'] = '';
    +      }
    +    }
    +    else if (!is_numeric($exploded[count($exploded) - 1])) {
    +      $facet_settings = $args['adapter']->getFacetSettingsGlobal($args['facet']);
    +      $vocabulary = !empty($facet_settings->settings['pretty_paths_taxonomy_no_id_vocabulary']) ? $facet_settings->settings['pretty_paths_taxonomy_no_id_vocabulary'] : NULL;
    +      $terms = taxonomy_get_term_by_name($args['value'], $vocabulary);
    +      $term = reset($terms);
    +      if (is_object($term)) {
    +        $args['value'] = $term->tid;
    +      }
    +      else {
    +        $args['value'] = '';
    +      }
    +    }
    

    quite some code duplication across the two if clauses

+++ b/plugins/coders/facetapi_pretty_paths_coder_dates.inc
@@ -0,0 +1,84 @@
+    //decode to solr dates diapason

please respect coding standards:
// Decode to solr dates diapason.

also i have to admit that i haven't heard of diapason before and i a quick google on "solr date diapason" didn't lead to any meaningful results. does using something like "value" instead work?

  1. +++ b/plugins/coders/facetapi_pretty_paths_coder_dates.inc
    @@ -0,0 +1,84 @@
    +    }
    ...
    +    if (count($all_dates) == 2) {
    +      $first_date_timestamp = strtotime($all_dates[0]);
    +      $first_date = date($solr_date_format_for_path, $first_date_timestamp);
    +
    +      $second_date_timestamp = strtotime($all_dates[1]);
    +      $second_date = date($solr_date_format_for_path, $second_date_timestamp);
    +    }
    +    else {
    +      $first_date_timestamp = strtotime($all_dates[0]);
    +      $first_date = date($solr_date_format_for_path, $first_date_timestamp);
    +
    +      $second_date_offset = '+1 ' . strtolower($facet_settings->settings['date_granularity']);
    +      $second_date = date($solr_date_format_for_path, strtotime($all_dates[0] . $second_date_offset));
    

    code duplication across if statements

  2. +++ b/plugins/coders/facetapi_pretty_paths_coder_dates.inc
    @@ -0,0 +1,84 @@
    +
    +
    

    unnecessary empty line

uzlov’s picture

Fixed code. Removed coder "taxonomy no id". Merged "taxonomy no id" functional with usual taxonomy coder (this is coder more likely).

uzlov’s picture

rv0’s picture

Patch addresses 2 issues:

- terms are displayed in urls with capitalization retained.
- pretty_paths_taxonomy_coder_strategy is not always set, so check for it.

I have the impression the code is still doing things to terms when it is not configured to do so?

My interdiff kinda failed (dunno why), but here's the relevant part:

diff --git a/plugins/coders/facetapi_pretty_paths_coder_taxonomy.inc b/plugins/coders/facetapi_pretty_paths_coder_taxonomy.inc
index de63a17..ac46b78 100644
--- a/plugins/coders/facetapi_pretty_paths_coder_taxonomy.inc
+++ b/plugins/coders/facetapi_pretty_paths_coder_taxonomy.inc
@@ -17,7 +17,8 @@ class FacetApiPrettyPathsCoderTaxonomy extends FacetApiPrettyPathsCoderDefault {
    */
   public function encodePathSegment(array $args) {
     $facet_settings = $args['adapter']->getFacetSettingsGlobal($args['facet']);
-    if ($facet_settings->settings['pretty_paths_taxonomy_coder_strategy'] == 'taxonomy_coder') {
+
+    if (isset($facet_settings->settings['pretty_paths_taxonomy_coder_strategy']) && $facet_settings->settings['pretty_paths_taxonomy_coder_strategy'] == 'taxonomy_coder') {
       if ($term = taxonomy_term_load($args['segment']['value'])) {
         $args['segment']['value'] = $this->prettyPath($term->name) . '-' . $term->tid;
       }
@@ -30,10 +31,10 @@ class FacetApiPrettyPathsCoderTaxonomy extends FacetApiPrettyPathsCoderDefault {
 
         $terms = taxonomy_get_term_by_name($term->name, $vocabulary);
         if (count($terms) == 1) {
-          $args['segment']['value'] = $term->name;
+          $args['segment']['value'] = $this->prettyPath($term->name);
         }
         else {
-          $args['segment']['value'] = $term->name . '-' . $term->tid;
+          $args['segment']['value'] = $this->prettyPath($term->name) . '-' . $term->tid;
         }
       }
     }

you have my vote for the taxonomy functionality as provided by the patch.

dasjo’s picture

Status: Needs review » Needs work

the provided patches still include the "no id" coder, which i'd like to be solved by #1981578: Allow to remove "Taxonomy Vocabulary" from urls

i'd suggest turning this one into a stand-alone "dates coder" patch.

andypost’s picture

and tests

dasjo’s picture

andypost, was that comment intentional? not sure about the tag :)

andypost’s picture

@dasjo I'm trying to follow facetapi 8 so just marked to check later. I found that few sites still using the patch #7, so maybe d8 version would be a different

uzlov’s picture

Updated patch to current state of branch 7.x-1.x.
Removed "no id" coder. For now stand-alone "dates coder" patch.
Added some little fixes (translation for delimiter of two dates etc).
@dasjo please check.

andypost’s picture

Status: Needs work » Needs review
dasjo’s picture

Status: Needs review » Needs work

hi andypost & uzlov,

thanks for getting this going again, your contribution is very much appreciated :)

i only have a few small remarks but it looks like we can get this in soon:

  1. +++ b/facetapi_pretty_paths.module
    @@ -313,7 +351,8 @@ function facetapi_pretty_paths_facetapi_facet_info_alter(array &$facet_info, arr
    +    ¶
    

    please make sure that indentation (spaces) are correct

  2. +++ b/plugins/coders/facetapi_pretty_paths_coder_dates.inc
    @@ -0,0 +1,86 @@
    +//      $value = date($date_format_for_path, strtotime($first_date)) . '_to_' . date($date_format_for_path, strtotime($second_date));
    

    can we remove that one?

  3. +++ b/plugins/coders/facetapi_pretty_paths_coder_dates.inc
    @@ -0,0 +1,86 @@
    +    $delimiter = t('@date1_to_@date2', array('@date1' => '', '@date2' => ''));
    +    $all_dates = explode($delimiter, $args['value']);
    

    could you add a comment, so that $arg['value] is expected to be like TIMESTAMP1_to_TIMESTAMP2

  4. +++ b/plugins/coders/facetapi_pretty_paths_coder_dates.inc
    @@ -0,0 +1,86 @@
    +    if ($first_date != '' && $second_date != '') {
    

    Is there a specific reason why only the date part without times is respected? Probably because you want to to be compact. We could add an optional setting so that aliases contain the time part as well?

uzlov’s picture

Rewrited coder-decoder, added time to path. Decided don't use one more settings options. Option for date (and time) format will be enough.

dasjo’s picture

Title: New coders for Facet API Pretty Paths. Coder for dates and Coder for taxonomy without ID. » Date coder for pretty paths

thanks, looks good haven't tested it yet. adapting issue title

dasjo’s picture

Issue tags: -taxonomy coder