I am using Composer to download third-party modules to my Drupal 8 repository.
I have a requirement that involves all of the functionality that module gives but there are unfortunately 2 lines of code that I need to remove in a PHP file in the module_name/src/Helper folder.
The lines I've commented out are to stop the request to open a jQuery UI dialog box.
I'm curious as to what you guys think. It is a requirement from the client that I have this functionality in place.
Here is the code snippet taken from the Ajax Add To Cart Module:
namespace Drupal\ajax_add_to_cart\Helper;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\ajax_add_to_cart\Ajax\ReloadCommand;
use Drupal\block\Entity\Block;
use Drupal\Core\Ajax\ReplaceCommand;
/**
* Class AjaxCartHelper.
*
* @package Drupal\modules\ajax_add_to_cart
*/
class AjaxCartHelper {
/**
* Ajax add to cart response.
*
* @param string $form_id
* Form id.
* @param object $response
* Response object to store information.
*
* @return object
* Return response object.
*/
public function ajaxAddToCartAjaxResponse($form_id, $response) {
// Adding modal window.
$options = [
'width' => 250,
'height' => 300,
];
$settings = [
$form_id => [
'title' => t('Successful Added'),
'message' => t('Cart Updated Successfully'),
],
];
$title = $settings[$form_id]['title'];
$message = $_SESSION['messages']['status'][0]->__toString();
if (!empty($this->cartBlock)) {
// ****LINE TO REMOVE****
$response->addCommand(new OpenModalDialogCommand($title, $message, $options));
// **********************
}
else {
$customblock = $this->container->get('plugin.manager.block')->createInstance('commerce_cart', []);
$render = $customblock->build();
// ****LINE TO REMOVE****
$response->addCommand(new OpenModalDialogCommand($title, $render, $options));
// **********************
}
$response->addCommand(new ReplaceCommand('.block-commerce-cart', $this->cartBlock));
$response->addCommand(new ReloadCommand());
unset($_SESSION['messages']);
return $response;
}
}
I've added the comment - / ****LINE TO REMOVE**** to the lines that need to be removed
My ideas are:
- Duplicate the whole module so that it's custom and use that as the solution (even though module updates won't affect the custom module and i'll have to update it each time)
- Comment the two lines out and then update the third-party module
Is there any other methods I'm missing? I've seen the libraries override but thats for the purposes of theming purposes- JS and CSS, I just wondered if theres anything out there in the drupal community fro overriding the PHP that modules provide?
It must be a common requirement by Drupal Devs.