Fatal error following instructions

Created on 11 June 2024, 17 days ago
Updated 18 June 2024, 10 days ago

Problem/Motivation

Looking to add the module to my website so when content editors create new content they can choose to post to twitter (x)

Following the instructions we see the fatal errror like:

Fatal error: Declaration of Drupal\social_post_x\Plugin\Network\XPost::initSdk() must be compatible with Drupal\social_api\Plugin\NetworkBase::initSdk(): mixed in /opt/drupal/web/modules/social_post_x/src/Plugin/Network/XPost.php on line 30

Steps to reproduce

1. Install the required modules

2. Enable the modules

  • Workflows
  • Rules

3. Install this module

Rules Configuration

  1. Navigate to Configuration > Rules (/admin/config/workflow/rules) and click "Add reaction rule".
  2. Select a React on event value (e.g. "After saving a new content node").
  3. Set a Label for the rule (e.g. "New content node tweet").
  4. Click "Save".
  5. On the rule edit page, click "Add action".
  6. Select the "X Tweet" action under the "Social Post" option group in the Action field.
  7. Click "Continue".
  8. Input the text to be tweeted -- e.g. A new article "{{ node.title.value }}" has been published on my website at {{ node | entity_url }}
  9. Click "Save".
  10. Add other conditions and/or actions as desired.
  11. Click "Save".

On step 7. we see the Fatal error above.

Proposed resolution

Looks like there may be an issue on line 30 in XPost.php?

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom dave_______1

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dave_______1
  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Hi Dave

    Thanks for posting this issue.

    I have this working locally but I am using with

                "name": "drupal/social_api",
                "version": "3.1.0",
    

    I have not really looked into this but it sounds like something may have broken this in social_api 4.x

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    It looks like the signature has changed on 4.x branch. I n particular sdk is a mixed type. mixed type was introduced in php 8.0. Probably this needs updating so that the child class has the same.

    e.g.

    3.x

     /**
       * Sets the underlying SDK library.
       *
       * @return mixed
       *   The initialized 3rd party library instance.
       *
       * @throws \Drupal\social_api\SocialApiException
       *   If the SDK library does not exist or other validation fails.
       */
      abstract protected function initSdk(): mixed;
    
    

    4.x

      /**
       * The SDK client.
       *
       * @var mixed
       */
      protected mixed $sdk = NULL;
    

    I think the quick fix (and to check this) would be to make sure you are using social post 3.x

    e.g. in your project require

    "drupal/social_post": "^3.0",

    1. Probably need to specify a version of social_post that is compatible currently 3.x
    2. Test with 4.x version and a make sure signature is the same
    3. Make 4.x compatible

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Also created 1.0.0 release

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Sorry previous comments about the signature were incorrect. Please ignore.

    One thing I was wondering is how you managed to install social_api 4.x as from what I can see social_post has dependency of 3.x?

    The latest version of social_post is still 3.x afict

    https://git.drupalcode.org/project/social_post/-/blob/3.x/composer.json?...

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Ok so for social api 4.x we have social_api/src/Plugin/NetworkInterface.php

    https://git.drupalcode.org/project/social_api/-/blob/4.0.x/src/Plugin/Ne...

    <?php
    
    namespace Drupal\social_api\Plugin;
    
    use Drupal\Component\Plugin\PluginInspectionInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    
    /**
     * Defines an interface for Social Network plugins.
     */
    interface NetworkInterface extends PluginInspectionInterface, ContainerFactoryPluginInterface {
    
      /**
       * Gets the underlying SDK library.
       *
       * @return mixed
       *   The SDK client.
       */
      public function getSdk(): mixed;
    
    }
    

    where as in 3.x branch it is just:

    <?php
    
    namespace Drupal\social_api\Plugin;
    
    use Drupal\Component\Plugin\PluginInspectionInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    
    /**
     * Defines an interface for Social Network plugins.
     */
    interface NetworkInterface extends PluginInspectionInterface, ContainerFactoryPluginInterface {
    
      /**
       * Gets the underlying SDK library.
       *
       * @return mixed
       *   The SDK client.
       */
      public function getSdk();
    
    }
    
    

    Notice how the signature has changed

    in

    we have

      /**
       * {@inheritdoc}
       */
      protected function initSdk() {
        $class_name = '\Abraham\TwitterOAuth\TwitterOAuth';
        if (!class_exists($class_name)) {
          throw new SocialApiException(sprintf('The PHP SDK for X could not be found. Class: %s.', $class_name));
        }
    
        /** @var \Drupal\social_post_x\Settings\XPostSettings $settings */
        $settings = $this->settings;
    
        retu

    so perhaps this need to be updated so that we have

    protected function initSdk(): mixed {

    That said I am still not sure why you have social_api 4.x installed?

  • πŸ‡¬πŸ‡§United Kingdom 2dareis2do

    Ok so it looks like social_post 4.x that is compatible with social_api 4.x is in the works.

    https://www.drupal.org/project/social_post/issues/3307661 πŸ’¬ Support Social API v4 RTBC

    Perhaps it makes sense to add a a new branch/tag that supports that?

Production build 0.69.0 2024