Skip to content
Snippets Groups Projects
Commit 9374018c authored by Ahmad Abbad's avatar Ahmad Abbad
Browse files

Issue #3363538 by ahmad-abbad Revert changes

parent c074512e
Branches 1.0.x
No related merge requests found
INTRODUCTION:
This module offers a feature that allows you to retrieve image posts associated
with an Instagram account.
To learn more about the module, please visit the project page:
This module offers a feature that allows you to retrieve image posts associated with an Instagram account. To learn more about the module, please visit the project page:
https://www.drupal.org/project/instagram_posts_block
REQUIREMENTS:
To install the library, it is recommended to use composer.
Run the following command:
To install the library, it is recommended to use composer. Run the following command:
composer require drupal/instagram_posts_block
......@@ -20,14 +18,11 @@ CONFIGURATION:
After installing the module,
you will find a new block called "Instagram Posts Block".
Go to Structure -> Block layout,
and click on "Place block" in the desired region.
Go to Structure -> Block layout, and click on "Place block" in the desired region.
In the block modal's search bar,
search for "Instagram Posts Block" and select it.
In the block modal's search bar, search for "Instagram Posts Block" and select it.
The newly added block will provide options to add the access token and adjust
other settings to control the display of the Instagram feed.
The newly added block will provide options to add the access token and adjust other settings to control the display of the Instagram feed.
Author:
This module, "instagram_posts_block," was developed by Ahmad Abbad.
This module, "instagram_posts_block," was developed by Ahmad Abbad.
\ No newline at end of file
......@@ -2,4 +2,4 @@
display: flex;
gap: 15px;
margin-bottom: 30px;
}
}
\ No newline at end of file
......@@ -3,3 +3,8 @@ description: Provides an instagram feed in a block.
type: module
core_version_requirement: ^9 || ^10
package: Social
# Information added by Drupal.org packaging script on 2023-05-28
version: '1.0.0-alpha2'
project: 'instagram_posts_block'
datestamp: 1685283874
......@@ -2,7 +2,6 @@
/**
* @file
* Module file to addon functionality.
*/
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -45,7 +44,7 @@ function instagram_posts_block_theme() {
/**
* Function to get refreshed access token.
*/
function instagram_posts_block_get_refreshed_access_token($access_token) {
function get_refreshed_access_token($access_token) {
$client = \Drupal::httpClient();
$request = $client->request('GET', 'https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=' . $access_token, ['http_errors' => FALSE]);
......@@ -68,13 +67,9 @@ function instagram_posts_block_preprocess_block(&$variables) {
$token_expiry = $variables['elements']['#configuration']['token_timestamp'] + (86400 * 58);
if (time() >= $token_expiry) {
// Get the refreshed access token &
// build the updated config array of values.
$renewed_token = instagram_posts_block_get_refreshed_access_token($variables['elements']['#configuration']['access_token']);
$renewed_data = [
'token_timestamp' => time(),
'access_token' => $renewed_token,
];
// Get the refreshed access token & build the updated config array of values.
$renewed_token = get_refreshed_access_token($variables['elements']['#configuration']['access_token']);
$renewed_data = ['token_timestamp' => time(), 'access_token' => $renewed_token];
// Set the renewed access token and it's new timestamp.
$config = \Drupal::service('config.factory')->getEditable('block.block.' . $variables['elements']['#id']);
......
......@@ -8,7 +8,6 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;
/**
* Provides a 'Instagram Posts' block.
......@@ -27,20 +26,12 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
*/
private $httpClient;
/**
* A logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Client $http_client, LoggerInterface $logger) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, Client $http_client) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->httpClient = $http_client;
$this->logger = $logger;
}
/**
......@@ -88,7 +79,7 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
]);
}
catch (RequestException $e) {
$logger = $this->logger('HTTP Client error');
$logger = \Drupal::logger('HTTP Client error');
$logger->error($e->getMessage());
return;
}
......@@ -129,7 +120,7 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
'#title' => $this->t('Total no. of images to display'),
'#description' => $this->t('How many images in total to be displayed'),
'#min' => 1,
'#default_value' => $config['total_images'] ?? '',
'#default_value' => isset($config['total_images']) ? $config['total_images'] : '',
'#required' => TRUE,
];
$form['images_per_row'] = [
......@@ -137,7 +128,7 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
'#title' => $this->t('No. of images per row'),
'#min' => 1,
'#description' => $this->t('How many images to be displayed per row?'),
'#default_value' => $config['images_per_row'] ?? '',
'#default_value' => isset($config['images_per_row']) ? $config['images_per_row'] : '',
'#required' => TRUE,
];
$form['media_type'] = [
......@@ -149,7 +140,7 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
'IMAGE' => $this->t('Image'),
'VIDEO' => $this->t('Video'),
],
'#default_value' => $config['media_type'] ?? 'All',
'#default_value' => isset($config['media_type']) ? $config['media_type'] : 'All',
'#required' => TRUE,
];
$form['caption_option'] = [
......@@ -159,7 +150,7 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
'default' => $this->t('Default'),
'trimmed' => $this->t('Trimmed'),
],
'#default_value' => $config['caption_option'] ?? 'default',
'#default_value' => isset($config['caption_option']) ? $config['caption_option'] : 'default',
'#attributes' => [
'id' => 'field_caption',
],
......@@ -169,7 +160,7 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
'#title' => $this->t('Trimmed limit'),
'#field_suffix' => $this->t('characters'),
'#min' => 1,
'#default_value' => $config['trimmed_limit'] ?? 100,
'#default_value' => isset($config['trimmed_limit']) ? $config['trimmed_limit'] : 100,
'#states' => [
'visible' => [
':input[id="field_caption"]' => ['value' => 'trimmed'],
......@@ -180,13 +171,13 @@ class InstagramPostsBlock extends BlockBase implements ContainerFactoryPluginInt
'#type' => 'textarea',
'#title' => $this->t('Long Lived Access Token'),
'#description' => $this->t('Access Token to access insta feed?'),
'#default_value' => $config['access_token'] ?? '',
'#default_value' => isset($config['access_token']) ? $config['access_token'] : '',
'#required' => TRUE,
];
$form['token_timestamp'] = [
'#title' => $this->t('The time when the Access Token was created'),
'#type' => 'textfield',
'#default_value' => $config['token_timestamp'] ?? time(),
'#default_value' => isset($config['token_timestamp']) ? $config['token_timestamp'] : time(),
'#disabled' => 'TRUE',
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment