This module uses Open AI and generates meta descriptions for the different content types based on the title of each node.

User can enter the title of the node and click on the "Generate Metadata" button to generate the meta description for the node page. Based on the provided title, Open AI will generate a meta description for the node page and will be replaced by the Summary field.
The generated description will then be used as meta description on the search engines.

Project link

https://www.drupal.org/project/open_ai_metadata

Comments

vinaymahale created an issue. See original summary.

vinaymahale’s picture

Status: Active » Needs review
shashank5563’s picture

Thank you for applying! Reviewers will review the project files, describing what needs to be changed.

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.

To reviewers: Please read How to review security advisory coverage applications, What to cover in an application review, and Drupal.org security advisory coverage application workflow.

While this application is open, only the user who opened the application can make commits to the project used for the application.

Reviewers only describe what needs to be changed; they don't provide patches to fix what reported in a review.

avpaderno’s picture

Issue summary: View changes
shashank5563’s picture

Status: Needs review » Needs work

Fix PHPCS Issue.

vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,php  web/modules/open_ai_metadata/

FILE: /web/modules/open_ai_metadata/src/Form/MetadataConfigForm.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 5 WARNINGS AFFECTING 6 LINES
--------------------------------------------------------------------------------------------------
   1 | ERROR   | [x] End of line character is invalid; expected "\n" but found "\r\n"
  33 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
  88 | WARNING | [ ] Unused variable $api_model.
 111 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 112 | WARNING | [ ] Unused variable $values.
 120 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------


FILE: /web/modules/open_ai_metadata/src/Form/MetadataSettingsForm.php
---------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 6 WARNINGS AFFECTING 7 LINES
---------------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR   | [x] End of line character is invalid; expected "\n" but found "\r\n"
 34 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 43 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 46 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 55 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 74 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 77 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------


FILE: /web/modules/open_ai_metadata/open_ai_metadata.module
-----------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------
 1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"
-----------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
vinaymahale’s picture

Assigned: Unassigned » vinaymahale
vinaymahale’s picture

Hello everyone,

All the above PHPCS issues have been addressed and committed to branch 1.0.x

Except for the below error which I was not able to replicate

FILE: /web/modules/open_ai_metadata/open_ai_metadata.module
-----------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------
 1 | ERROR | [x] End of line character is invalid; expected "\n" but found "\r\n"

@shashank5563 can you please help replicate the issue for me? I ran the phpcs and it did not give me the above error!

Please validate the fixed errors and let me know if any changes are needed.

Thank you!

vinaymahale’s picture

Assigned: vinaymahale » Unassigned
Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work
  • 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 doesn't correctly use the Drupal API; the single points aren't ordered, not even by importance

src/Form/MetadataConfigForm.php

/**
 * Function to create the Metadata Config Form.
 */
class MetadataConfigForm extends ConfigFormBase {

That is the documentation comment for a class, not a function. There is no need to start the comment with Function to nor Class to.

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

The state service is used to store temporary information that is not human-edited, as Information types says. Human-edited information is stored in a configuration object; that is why the ConfigFormBase class has the config() method.

$this->messenger()->addMessage('Configurations saved successfully');

The first argument passed to MessengerInterface::addError(), MessengerInterface::addMessage(), MessengerInterface::addStatus(), and MessengerInterface::addWarning() must be a translatable string.
That message is not necessary, though, since the parent method already shows a message; it just needs to be called.

open_ai_metadata.module

$node = \Drupal::routeMatch()->getParameter('node');

The node object is already available in $variables['node'].

/**
 * Function to generate metadata from Open AI.
 */
function open_ai_metadata_generate_metadata(array &$form, FormStateInterface $form_state) {

The short description for an AJAX callback is similar to the one used for _update_ckeditor5_html_filter(). (The longer description is optional, as for hooks.)

/**
 * AJAX callback handler for filter_format_form().
 *
 * Used instead of editor_form_filter_admin_form_ajax from the editor module.
 */
vinaymahale’s picture

I have addressed the above feedback and changes have been committed to branch 1.0.x

State service has been now only used to store the Open AI access token to maintain the sensitive information.
Please validate the fixed security feedback and let me know if any changes are needed.

vinaymahale’s picture

Status: Needs work » Needs review
vinaymahale’s picture

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Reviewed & tested by the community

Thank you for your contribution! I am going to update your account.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the Slack #contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
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 all the reviewers.

avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.