Skip to content

Commit

Permalink
Merge pull request #22 from moreonion/twitter-change-to-x
Browse files Browse the repository at this point in the history
Rename Twitter share to Twitter / X
  • Loading branch information
torotil authored Aug 29, 2024
2 parents e32baf9 + f7505b0 commit 348025b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
namespace Drupal\share_light;

/**
* A channel for sharing via Twitter.
* A channel for sharing via Twitter / X.
*/
class Twitter extends ChannelBase {

/**
* Returns the channel's name.
*
* @return string
* Returns t('Twitter').
* Returns t('Twitter / X').
*/
public static function title() {
return t('Twitter');
return t('Twitter / X');
}

/**
Expand All @@ -25,16 +25,16 @@ public static function defaults() {
}

/**
* Adds configuration options for the `Twitter` channel to the field widget.
* Adds configuration options for the `Twitter / X` channel to the field widget.
*
* Allows the user to enter a default Tweet text.
* Allows the user to enter a default post text.
*/
public static function optionsWidget(array &$element, array $options) {
$title = static::title();
$element['text'] = array(
'#title' => t('Tweet text for @title.', ['@title' => $title]),
'#description' => t('Tweet text for @title.', ['@title' => $title]),
// 256 = 280 - 1 - 23 (tweet max-length - space - url in https)
'#title' => t('Post text for @title.', ['@title' => $title]),
'#description' => t('Post text for @title.', ['@title' => $title]),
// 256 = 280 - 1 - 23 (post max-length - space - url in https)
'#maxlength' => 256,
'#type' => 'textarea',
'#cols' => 60,
Expand All @@ -45,7 +45,7 @@ public static function optionsWidget(array &$element, array $options) {
}

/**
* Returns a link field containing a link to `https://twitter.com/intent/tweet`.
* Returns a link field containing a link to `https://x.com/intent/post`.
*
* @return array
* The link field's renderable array.
Expand All @@ -57,14 +57,14 @@ public function render() {

return array(
'title' => $this->title(),
'href' => 'https://twitter.com/intent/tweet',
'href' => 'https://x.com/intent/post',
'query' => [
'text' => $text,
'url' => !$text_includes_url ? $this->generateShareUrl('twitter_share') : '',
],
'attributes' => array(
'title' => t('Share this via Twitter!'),
'data-share' => 'twitter',
'title' => t('Share this via Twitter / X!'),
'data-share' => 'x',
'target' => '_blank',
),
);
Expand Down
2 changes: 1 addition & 1 deletion tests/ShareUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testShareUrls() {
$this->assertEquals('https://www.facebook.com/sharer.php', $fb['href']);
$this->assertStringContainsString('node/' . $node->nid, $fb['query']['u']);

$this->assertEquals('https://twitter.com/intent/tweet', $twitter['href']);
$this->assertEquals('https://x.com/intent/post', $twitter['href']);
$this->assertStringContainsString('node/' . $node->nid, $twitter['query']['text']);
$this->assertStringContainsString('utm_campaign=%5B' . $node->nid . '%5D', $twitter['query']['text']);

Expand Down

0 comments on commit 348025b

Please sign in to comment.