d8-contrib-modules / addthis

Port AddThis to D8
GNU General Public License v2.0
3 stars 13 forks source link

Investigate replacing AddThisWidgetJSURL with the D8 core URL class. #32

Open doylejd opened 9 years ago

doylejd commented 9 years ago

D8 provides a robust URL class as part of core. Look at replacing AddThisWidgetJsURL.php class with the core URL class.

ChuChuNaKu commented 9 years ago

I pulled down the d7 module to find where AddThisWidgetJsURL.php is being used. AddThisWidgetJSURL is being used on line 101 in AddThisScriptManager.php as part of the attachJsToElement function.

public function attachJsToElement(&$element) {
  if ($this->addthis->getWidgetJsInclude() != AddThis::WIDGET_JS_INCLUDE_NONE) {
    $widget_js = new AddThisWidgetJsUrl($this->getWidgetJsUrl());
    ...

There are three public function defined in AddThisWidgetJsUrl.php: removeAttribute, getFullUrl, and addAttribute. The removeAttribute function and getFullUrl functions don't appear to be used. The addAttribute function is used three times in AddThisScriptManager.php.

$pubid = $this->addthis->getProfileId();
if (isset($pubid) && !empty($pubid) && is_string($pubid)) {
  $widget_js->addAttribute('pubid', $pubid);
}

$async = $this->async;
if ($async) {
  $widget_js->addAttribute('async', 1);
}

$domready = $this->domready;
if ($domready) {
  $widget_js->addAttribute('domready', 1);
}

I'm now investigating how this addAttribute function can be replicated using the d8 core URL class. https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/class/Url/8

ChuChuNaKu commented 9 years ago

If the only function that is being called for AddThisWidgetJsUrl is addAttribute, and all addAttribute does is add an attribute to the query string, I think one of these core d8 classes can be used to replace it.

public static function Url::fromRoute https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AfromRoute/8

public static function Url::fromUri https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AfromUri/8

public function Url::construct https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3Aconstruct/8

public function Url::setOption https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/function/Url%3A%3AsetOption/8