[1.0.x] Social Media Platforms

Created on 22 February 2024, 10 months ago
Updated 18 September 2024, 3 months ago

Provides a block that allows to display a set of links to several social network profiles.

This module differs from Social Media Links Block and Field in the fact that the social network configuration does not live in the block, but in a separate settings form.

Project link

https://www.drupal.org/project/social_media_platforms →

📌 Task
Status

Fixed

Component

module

Created by

🇪🇸Spain guiu.rocafort.ferrer Barcelona

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

Comments & Activities

  • Issue created by @guiu.rocafort.ferrer
  • 🇮🇳India vishal.kadam Mumbai

    Thank you for applying!

    Please read Review process for security advisory coverage: What to expect → for more details and Security advisory coverage application checklist → to understand what reviewers look for. Tips for ensuring a smooth review → gives some hints for a smoother review.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • For the time this application is open, only your commits are allowed.
    • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application and no other user will be able to opt projects into security advisory policy.
    • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

    To the reviewers

    Please read How to review security advisory coverage applications → , Application workflow → , What to cover in an application review → , and Tools to use for reviews → .

    The important notes are the following.

    • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
    • Reviewers should show the output of a CLI tool → only once per application.
    • It may be best to have the applicant fix things before further review.

    For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues → .

  • 🇮🇳India vishal.kadam Mumbai
  • Status changed to Needs work 10 months ago
  • 🇮🇳India vishal.kadam Mumbai

    Fix phpcs issues.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml social_media_p
    latforms/
    
    FILE: social_media_platforms/config/schema/social_media_platforms.schema.yml
    -------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE                                                                              
    -------------------------------------------------------------------------------
     41 | ERROR | [x] Expected 1 newline at end of file; 2 found                                                
    -------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY                                                  
    -------------------------------------------------------------------------------
    
    
    FILE: social_media_platforms/css/social_media_platforms.theme.css
    -------------------------------------------------------------------------------
    FOUND 5 ERRORS AFFECTING 4 LINES
    -------------------------------------------------------------------------------
     1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
     1 | ERROR | [x] Additional whitespace found at start of file
     3 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     4 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     7 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
    -------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------
  • Status changed to Needs review 10 months ago
  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Thank you for the review @vishal.kadam.

    The phpcs issues have been fixed in the 1.0.x branch.
    For some reason the gitlab-ci template does not pick them up.
    Ready for review again.

  • Status changed to RTBC 8 months ago
  • 🇮🇳India vishal.kadam Mumbai

    Rest looks fine to me.

    Let’s wait for a Code Review Administrator to take a look and if everything goes fine, you will get the role.

  • Status changed to Needs work 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
    • A specific point may just be an example and may apply in other places
    • A review is about code that doesn't follow the coding standards, contains possible security issue, or does not correctly use the Drupal API; the single points are not ordered, not even by importance

    src/Form/SettingsForm.php

    There is no need to create a form class for a plugin settings: That is returned by the plugin's buildConfigurationForm() method.

    $config = $this->configFactory()->getEditable('social_media_platforms.settings');

    It is sufficient to call $this->config(), to get an editable configuration object.

    src/Plugin/Block/SocialMediaBlock.php

    final class SocialMediaBlock extends BlockBase implements ContainerFactoryPluginInterface {
    
      /**
       * Constructs a Drupalist object.
       *
       * @param array $configuration
       *   A configuration array containing information about the plugin instance.
       * @param string $plugin_id
       *   The plugin_id for the plugin instance.
       * @param mixed $plugin_definition
       *   The plugin implementation definition.
       * @param \Drupal\Core\Theme\ThemeManager $themeManager
       *   The theme manager.
       * @param \Drupal\Core\Extension\ExtensionPathResolver $pathResolver
       *   The path resolver.
       * @param \Drupal\Core\Config\ConfigFactory $config
       *   The config factory.
       */
    

    The short description is not for the class it should describe.

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Thank you for the review @apaderno.

    I have addressed the issues, and the code is ready to review again.

  • Status changed to Needs review 7 months ago
  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Changing the issue status to needs review.

  • 🇮🇳India rushiraval

    I am changing the issue priority as per issue priorities → .

  • 🇮🇳India vishal.kadam Mumbai

    I am changing priority as per Issue priorities → .

  • Status changed to Needs work 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    src/Form/SettingsForm.php

        foreach (self::SETTINGS as $key => $setting) {
          $form['display'][$key] = [
            '#type' => 'checkbox',
            '#title' => $setting,
            '#default_value' => $display_options[$key],
          ];
        }
    

    The form element title is not translatable.

      public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    
        $form = parent::buildConfigurationForm($form, $form_state);
        $form['help'] = [
          '#type' => 'link',
          '#url' => Url::fromRoute('social_media_platforms.settings'),
          '#title' => 'here',
          '#prefix' => 'The Social Media Platforms Links configuration can be modified ',
        ];
    
        return $form;
      }
    

    src/Plugin/Block/SocialMediaBlock.php

    The configuration form for a plugin does not give a link to page that allows to change the plugin settings. It shows the settings form, which also means the Drupal\social_media_platforms\Form\SettingsForm class is not necessary.

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Hi @avpaderno.

    Thank you again for your feedback.

    I have addressed the translatable elements issue as requested.
    Please notice that i added a @codingStandardsIgnoreLine because phpcs did not seem to understand that the value of the variable is comming from a literal ( defined as a CONST in the class itself ), and complained about "Only string literals should be passed to t() where possible".

    Regarding the block configuration, i am aware that this might not be the habitual way of handling it, but it is completely intentional, and part of how the module works. This module defines a block, that uses some settings defined outside the block itself. This is made on purpose to allow the domain_config subdomain to be able to define different variations of it for different domains. The link in the block settings form is merely a reminder for people that might be confused by how the module works, since there is another similar module "Social Media Block and Field" that works placing the configuration in the block itself. Please read the module description and let me know if you have any further questions about this issue.

  • Status changed to Needs review 4 months ago
  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Changing issue status to needs review.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    SocialMediaBlock::buildConfigurationForm() is still not returning a configuration form.

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Hi @avpaderno,

    I am a bit confused about what you are saying. SocialMediaBlock::buildConfigurationForm() is getting the form from the parent, and then adding a link element before returning it. The only reason i could think of this not being a good practice, might be the fact that the function is not adding any form element, it is just adding a link. I could remove the buildConfigurationForm method and add a form_alter in the .module file to add the link instead, would that be a more acceptable practice ?

  • Status changed to Needs work 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The following code is not building a form. It is giving a link to a page where a form can be found. That is not building a form.

      /**
       * {@inheritdoc}
       */
      public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    
        $form = parent::buildConfigurationForm($form, $form_state);
        $form['help'] = [
          '#type' => 'link',
          '#url' => Url::fromRoute('social_media_platforms.settings'),
          '#title' => $this->t('here'),
          '#prefix' => $this->t('The Social Media Platforms Links configuration can be modified') . ' ',
        ];
    
        return $form;
      }
    

    BlockBase just build the part of the form that is common for all the plugins, but that is not the full form for a plugin. That is why ViewsBlockBase::buildConfigurationForm() uses the following code.

    public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
        $form = parent::buildConfigurationForm($form, $form_state);
        // Set the default label to '' so the views internal title is used.
        $form['label']['#default_value'] = '';
        $form['label']['#access'] = FALSE;
        // Unset the machine_name provided by BlockForm.
        unset($form['id']['#machine_name']['source']);
        // Prevent users from changing the auto-generated block machine_name.
        $form['id']['#access'] = FALSE;
        $form['#pre_render'][] = '\\Drupal\\views\\Plugin\\views\\PluginBase::preRenderAddFieldsetMarkup';
        // Allow to override the label on the actual page.
        $form['views_label_checkbox'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Override title'),
            '#default_value' => !empty($this->configuration['views_label']),
        ];
        $form['views_label_fieldset'] = [
            '#type' => 'fieldset',
            '#states' => [
                'visible' => [
                    [
                        ':input[name="settings[views_label_checkbox]"]' => [
                            'checked' => TRUE,
                        ],
                    ],
                ],
            ],
        ];
        $form['views_label'] = [
            '#title' => $this->t('Title'),
            '#type' => 'textfield',
            '#default_value' => $this->configuration['views_label'] ?: $this->view
                ->getTitle(),
            '#states' => [
                'visible' => [
                    [
                        ':input[name="settings[views_label_checkbox]"]' => [
                            'checked' => TRUE,
                        ],
                    ],
                ],
            ],
            '#fieldset' => 'views_label_fieldset',
        ];
        if ($this->view->storage->access('edit') && \Drupal::moduleHandler()->moduleExists('views_ui')) {
            $form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore. (Try changing it directly in <a href=":url">@name</a>.)', [
                ':url' => Url::fromRoute('entity.view.edit_display_form', [
                    'view' => $this->view->storage->id(),
                    'display_id' => $this->displayID,
                ])
                    ->toString(),
                '@name' => $this->view->storage->label(),
            ]);
        }
        else {
            $form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore.');
        }
        return $form;
    }
    

    That is the code to build a form for a plugin.

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    So if i remove the buildConfigurationForm method for the class and implement a form_alter hook, would this be considered a better approach for this use case ? @avpaderno

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    No, that would not be a better approach. The method to implement is buildConfigurationForm(), which needs to return the form elements, not the build array for a link to a different page containing a form.

  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Hi @avpaderno

    The thing is that this is made on purpose, and it is part of how this module work and makes sense. The fact that the configuration is in a separate settings form, allows the submodule from domain (domain_config) to override the settings for different domains. If i would add the configuration form at the block itself, then this module would not have any reason to exist, because the "Social Media Links Block and Field" module ( https://www.drupal.org/project/social_media_links → ) would have the same functionality.

    If this is not acceptable to grant the security advisory coverage, let me know and we can close the issue, so we don't waste each other's time. I will try to qualify for the security advisory coverage when i have a chance to contribute another Drupal module and open a new issue.

  • Status changed to Needs review 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    In that case, you do not need to implement buildConfigurationForm() and using a form class is correct. I should have been explicit and say:

    If the plugin configuration is not used outside the plugin, the form class must be replaced from the buildConfigurationForm() method.

  • Status changed to Needs work 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review 3 months ago
  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Hi @avpaderno

    I have removed the buildConfigurationForm and implemented a form_alter hook instead.
    Marking as needs review.

  • Status changed to Needs work 3 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    It seems I was not clear: There is no need to implement hook_form_alter() because there is already a form class that is accessible from a route.
    hook_form_alter() would not be necessary even in the case the plugin settings form is built from a plugin method.

  • Status changed to Needs review 3 months ago
  • 🇪🇸Spain guiu.rocafort.ferrer Barcelona

    Hi @avpaderno,

    I removed the hook_form_alter. Please review.

    Thank you for your patience.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Thank you for your contribution and for your patience with the review process!

    I am going to update your account so you can opt into security advisory coverage any project you create, including the projects you already created.

    These are some recommended readings to help you with maintainership:

    You can find more contributors chatting on Slack → or IRC → in #drupal-contribute. So, come hang out and stay involved → !
    Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review → . I encourage you to learn more about that process and join the group of reviewers.

    I thank the dedicated reviewers as well.

  • Assigned to apaderno
  • Status changed to Fixed 3 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024