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

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

Open
doylejd opened this issue Aug 18, 2015 · 2 comments
Open
Assignees

Comments

@doylejd
Copy link
Contributor

doylejd commented Aug 18, 2015

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

@ChuChuNaKu
Copy link

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
Copy link

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%3A__construct/8

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants