Skip to content

Commit

Permalink
Issue #2749119 by ryanissamson, scottrigby: Adds variable that overri…
Browse files Browse the repository at this point in the history
…des base canonical url (#72)

- If a url is supplied, the base portion is overridden.
- This could probably be improved with validation on
  the field to prevent malformed urls.

https://www.drupal.org/node/2749119
  • Loading branch information
ryanissamson authored and scottrigby committed Jun 16, 2016
1 parent 20b45bc commit c506131
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions fb_instant_articles.install
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function fb_instant_articles_uninstall() {
variable_del('fb_instant_articles_analytics_embed_code');
variable_del('fb_instant_articles_enable_logging');
variable_del('fb_instant_articles_bypass_composer_manager');
variable_del('fb_instant_articles_canonical_url_override');
}

/**
Expand Down
8 changes: 8 additions & 0 deletions includes/admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ function fb_instant_articles_settings() {
'#description' => t('Sends Facebook Instant Articles SDK logging messages to Drupal watchdog.'),
);

// Add the Canonical URL override.
$form['fb_instant_articles_canonical_url_override'] = array(
'#type' => 'textfield',
'#title' => t('Canonical URL override'),
'#default_value' => variable_get('fb_instant_articles_canonical_url_override', ''),
'#description' => t('If you need to override the base url portion of the canonical URL, you can do so here. This may be helpful for development domains or necessary if admin users perform tasks that trigger Facebook requests from alternate domains. This URL should not include a trailing slash (e.g. http://drupal.org).'),
);

$form = system_settings_form($form);
return $form;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ public function map() {
}

private function addCanonicalURL() {
$canonical_override = variable_get('fb_instant_articles_canonical_url_override', '');
$path = entity_uri($this->entity_type, $this->entity);
$this->instantArticle->withCanonicalUrl(url($path['path'], array('absolute' => TRUE)));
if (empty($canonical_override)) {
$canonical_url = url($path['path'], array('absolute' => TRUE));
}
else {
$canonical_url = $canonical_override . url($path['path']);
}
$this->instantArticle->withCanonicalUrl($canonical_url);
}

private function addHeaderFromProperties() {
Expand Down

0 comments on commit c506131

Please sign in to comment.