Skip to content

Commit

Permalink
Merge pull request #63 from localgovdrupal/62/rename-social-post-module
Browse files Browse the repository at this point in the history
renames social post module
  • Loading branch information
markconroy committed Jun 19, 2024
2 parents b935c3c + bc2c93d commit b21ccee
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: LocalGov Elections Reporting Social Post Integration
description: Social API integration
name: "DEPRECATED: LocalGov Elections Reporting Social"
description: "Deprecated: Use LocalGov Elections Reporting Social Post Integration instead."
type: module
package: LocalGov Drupal
core_version_requirement: ^9 || ^10
lifecycle: deprecated
lifecycle_link: 'https://github.com/localgovdrupal/localgov_elections_reporting/pull/63'

dependencies:
- localgov_elections_reporting:localgov_elections_reporting
Expand Down
22 changes: 22 additions & 0 deletions modules/localgov_elections_reporting_social_post/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# LocalGov Elections Reporting Social Post Integration

This module provides an integration with the Drupal module [Social API](https://www.drupal.org/project/social_api). We
have provided a Twitter posting integration which you can use to post to Twitter once you have finalised the votes for
an area.

At present, we only support Twitter. You are free to add your own integrations with social API if that doesn't work for
you. We may add further integrations down the line but that is not planned at present.

See the [documentation](../../docs/index.md) for details on how to use this when running an election.

## Configuration

1. You will need to obtain and API key and secret for Twitter/X and enter them at `/admin/config/social-api/social-post/twitter`. Twitter/X provide details on how to do this at https://developer.twitter.com/en/docs/authentication/oauth-1-0a/api-key-and-secret.
2. You then need to link each user who will be posting to Twitter/X from the site to a Twitter account.
3. Each user needs to login and visit their profile and click 'Add account' in the '`'Social Post Twitter' section.
4. This will take you to a Twitter/X screen to authorise access to the account.
5. Once authorised you will be taken back to the user profile showing the account listed.

## Default Tweet

You can edit the default tweet at `/admin/config/elections/social-post-integration/settings`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message_template: 'Candidate [node:field_winning_candidate:entity:field_candidate_forenames] [node:field_winning_candidate:entity:field_candidate] won for the [node:field_winning_candidate:entity:field_party] party with [node:field_winning_candidate:entity:field_votes] votes in [node:field_area_name:value]!'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Schema for the configuration files of the Election Social Integration module.
localgov_elections_reporting_social_post.settings:
type: config_object
label: 'Election Social Integration settings'
mapping:
message_template:
type: string
label: 'Message template'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: LocalGov Election Reporting Social Post Integration
description: Social API integration
type: module
package: Localgov Drupal
core_version_requirement: ^9 || ^10

dependencies:
- drupal:localgov_elections_reporting
- drupal:social_post
- drupal:social_post_twitter
- drupal:token
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @file
* LocalGov Election Reporting Social Post install file.
*/

/**
* Implements hook_install().
*/
function localgov_elections_reporting_social_post_install() {
// Check if localgov_election_reporting_social_post module is installed.
// If so, uninstall it, so we can use this module instead.
if (\Drupal::moduleHandler()->moduleExists('localgov_election_reporting_social_post')) {
\Drupal::service('module_installer')->uninstall(['localgov_election_reporting_social_post']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
localgov_elections_reporting_social_post.settings:
title: Election Social Integration Settings
parent: social_api.admin_config
route_name: localgov_elections_reporting_social_post.settings
weight: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* @file
* LocalGov Election Reporting Social Post module file.
*/

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function localgov_elections_reporting_social_post_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$node = $form_state->getFormObject()->getEntity();
if ($node->bundle() == "division_vote") {
$form['actions']['save_and_add_areas'] = $form['actions']['submit'];
$form['actions']['save_and_add_areas']['#value'] = t("Save and Tweet");
$form['actions']['save_and_add_areas']['#submit'][] = "localgov_elections_reporting_social_post_save_and_tweet";
$form['actions']['save_and_add_areas']['#weight'] = 100;
}
}

/**
* Save and tweet submit function callback.
*/
function localgov_elections_reporting_social_post_save_and_tweet($form, FormStateInterface $form_state) {
\Drupal::request()->query->remove('destination');
if ($node = $form_state->getFormObject()->getEntity()) {
if ($id = $node?->id()) {
$form_state->setRedirectUrl(Url::fromRoute('localgov_elections_reporting_social_post.area_vote_social_post',
['node' => $id])
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
can access election social posting:
title: 'Can access election social posting'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
localgov_elections_reporting_social_post.area_vote_social_post:
path: '/node/{node}/social-post'
defaults:
_title: 'Area Vote Social Post'
_form: 'Drupal\localgov_elections_reporting_social_post\Form\AreaVoteSocialPostForm'
requirements:
_permission: 'can access election social posting'
node: \d+
options:
_node_operation_route: TRUE
parameters:
node:
type: entity:node

localgov_elections_reporting_social_post.settings:
path: '/admin/config/elections/social-post-integration/settings'
defaults:
_title: 'Settings'
_form: 'Drupal\localgov_elections_reporting_social_post\Form\SettingsForm'
requirements:
_permission: 'administer site configuration'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: LocalGov Elections Reporting Social Post Integration
description: Social API integration
type: module
package: LocalGov Drupal
core_version_requirement: ^9 || ^10

dependencies:
- localgov_elections_reporting:localgov_elections_reporting
- social_post:social_post
- social_post_twitter:social_post_twitter
- drupal:token
Loading

0 comments on commit b21ccee

Please sign in to comment.