Commit 7d58a741 authored by Pasindu Wijesekera's avatar Pasindu Wijesekera
Browse files

Issue 2890209 by danuddara,mayank_jeshti: commited drupal code standard changes

parent 5650f893
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
Introduction
EnquiryCart module will be able to add an enquiry button as a block to any node type.
It will have the functionality to add/delete node titles to a cart and finally users can use a simple form to send the enquiry.
EnquiryCart module will be able to add an enquiry 
button as a block to any node type.
It will have the functionality to add/delete node titles to a cart 
and finally users can use a simple form to send the enquiry.


Installation
1. Go to 'extend' from the admin menu and install the module.
2. Remember to go to the 'structure' > 'Block' from admin menu and place the 'Enquiry button' block anywhere you need.
3. Click on 'Configure' option to setup your own custom configuration to the button page title, button titles, email and wordings.
4. You can use the 'email' field in the configuration to define a different email address for receive the enquiries rather than the site email.
2. Remember to go to the 'structure' > 'Block' from admin menu 
   and place the 'Enquiry button' block anywhere you need.
3. Click on 'Configure' option to setup your own custom configuration 
   to the button page title, button titles, email and wordings.
4. You can use the 'email' field in the configuration to define a 
   different email address for receive the enquiries rather than the site email.
+10 −6
Original line number Diff line number Diff line
@@ -2,9 +2,13 @@

/**
 * @file
 * Implements hook_install().
 * This is created for clearing out the session when installed again.
 * Installation configurations for module.
 */

/**
 * Implements hook_install() for enquirycartbuttonform submit.
 *
 * This is created for clearing out the session when installed again.
 */
function enquirycart_install() {

+0 −1
Original line number Diff line number Diff line
@@ -21,4 +21,3 @@ enquirycart.settings:
    _title: 'Enquiry configuration'
  requirements:
    _permission: 'administer site configuration'
    
 No newline at end of file
+91 −104
Original line number Diff line number Diff line
<?php

/**
 * 
 * Contains \Drupal\enquirycart\Controller\EnquirycartController.
 * have empty line in between everything,
 * have a space infornt of the comments.
 */

namespace Drupal\enquirycart\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\enquirycart\Form;


/**
 * Enquiry contoller class.
 */
class EnquirycartController extends ControllerBase {

  private $config;


  /**
   * Constructor to set the config.
   */
  public function __construct() {
    $this->config = \Drupal::config('enquirycart.settings');

  }

  public function getTitle()
  {
  /**
   * Getconfig title and return  .
   */
  public function getTitle() {

    $title = $this->config->get('title');

    return $title;
  }

  public  function getEnquiryBasket()
  {
  /**
   * Get enquiry basket.
   */
  public  function getEnquiryBasket() {
    $request = \Drupal::request();

    $session = $request->getSession();

      $arraychgeck = null;
    $arraychgeck = NULL;
    $value = $session->get('enquire');

    if (!empty($value)) {

      $values['addproducts'] = array(
      $values['addproducts'] = [
        '#type' => 'markup',
        '#prefix' => '<div class="enquiremessge-full">',
        '#suffix' => '</div>',
        '#markup' => $this->config->get('instructions.basketfull'),
      );     
          
      ];

      $arraychgeck = array_chunk($value, 1);

      $arraykeys = array_keys($value);
      foreach($arraychgeck as $key=>$value)
      {
           $options['attributes'] =  array('rel'=>'nofollow');
      foreach ($arraychgeck as $key => $value) {
        $options['attributes'] = ['rel' => 'nofollow'];
        $value['operation'] = Link::fromTextAndUrl($this->t('Delete'), Url::fromRoute('enquirycart.deleteEnquiryBasket', ['eid' => $arraykeys[$key]], $options));
        $arraychgeck[$key] = $value;
      }

        $values['basket'] = array(
      $values['basket'] = [
        '#type' => 'table',
          '#header' => array($this->t('Product Names')),
        '#header' => [$this->t('Product Names')],
        '#default' => 'No products have been added to the basket',
          '#rows' => (!empty($arraychgeck))? $arraychgeck: array('No products have been added to the basket') ,
         );
         
        '#rows' => (!empty($arraychgeck)) ? $arraychgeck : ['No products have been added to the basket'] ,
      ];

      $builtForm = \Drupal::formBuilder()->getForm('Drupal\enquirycart\Form\EnquiryForm');
      $values['form'] = $builtForm;

        
      
    }
    else {

          
           $values['noproductsinbasket'] = array(
      $values['noproductsinbasket'] = [
        '#type' => 'markup',
        '#prefix' => '<div class="enquiremessge-empty">',
        '#suffix' => '</div>',
        '#markup' => $this->config->get('instructions.basketempty'),
        '#weight' => -1,
              );
      ];

    }

      
   
     
   
      
    return $values;
  }

  
  public function  deleteFromEnquiryBasket($eid)
  {
  /**
   * Delete item from the basket.
   *
   * @param int $eid
   *   URL value passsed from enquirybasket/{eid}/delete.
   */
  public function deleteFromEnquiryBasket($eid) {
    $request = \Drupal::request();
    $session = $request->getSession();

      $arraychgeck = null;
    $value = $session->get('enquire');


      if(isset($value[$eid]))
      {
     
       $message = $this->t("'@prod' has been removed from the enquiry basket.",array("@prod"=>$value[$eid]));
    if (isset($value[$eid])) {
      $message = $this->t("'@prod' has been removed from the enquiry basket.", ["@prod" => $value[$eid]]);
      unset($value[$eid]);
      $session->set('enquire', $value);
      drupal_set_message($message);

    }

      
    return $this->redirect('enquirycart.getEnquiryBasket');
  }

+98 −102
Original line number Diff line number Diff line
<?php

/**
 * The configuration file for enquiry form
 */

namespace Drupal\enquirycart\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

class EnquiryConfigForm extends ConfigFormBase
{
/**
 * Enquiry cart config form.
 */
class EnquiryConfigForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
@@ -20,68 +19,67 @@ class EnquiryConfigForm extends ConfigFormBase

  /**
   * {@inheritdoc}
     * Set the configurations that is editable 
   */
  public function getEditableConfigNames() {
        return array(
    return [
      'enquirycart.settings',
        );
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $config = $this->config('enquirycart.settings');

    $site_email = $config->get('enquirycart.email');
          if(empty($site_email))
            {
    if (empty($site_email)) {
      $system_site_config = \Drupal::config('system.site');
      $site_email = $system_site_config->get('mail');
    }

         $form['title'] = array(
    $form['title'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Title of the page'),
      '#default_value' => $config->get('title'),
      '#description' => $this->t('Type in the page title that you want to display in the enquiry basket'),
          );  
    ];

          $form['email'] = array(
    $form['email'] = [
      '#type' => 'email',
      '#title' => $this->t('Email'),
      '#default_value' => $site_email,
      '#description' => $this->t('Type in the email address that you need to send the enquiry to. By default it uses the site email configured in the website.'),
          ); 
    ];

          $form['addtoenquirybtntitle'] = array(
    $form['addtoenquirybtntitle'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Title of button "add to enquiry"'),
      '#default_value' => $config->get('buttonTitle'),
      '#description' => $this->t('Type in a title that you want to display in the button'),
          );  
    ];

          $form['sendbuttonTitle'] = array(
    $form['sendbuttonTitle'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Title of button "Send Enquiry"'),
      '#default_value' => $config->get('sendbuttonTitle'),
      '#description' => $this->t('Type in a title that you want to display in the button to send the enquiry'),
          );  
    ];

          $form['basketfullmsg'] = array(
    $form['basketfullmsg'] = [
      '#type' => 'text_format',
      '#title' => $this->t('Basket full message'),
      '#default_value' => $config->get('instructions.basketfull'),
      '#format' => 'full_html',
                          );
    ];

           $form['basketemptymsg'] = array(
    $form['basketemptymsg'] = [
      '#type' => 'text_format',
      '#title' => $this->t('Basket empty message'),
      '#default_value' => $config->get('instructions.basketempty'),
      '#format' => 'full_html',
                        );
        
        
    ];

    return parent::buildForm($form, $form_state);
  }
@@ -91,12 +89,11 @@ class EnquiryConfigForm extends ConfigFormBase
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

       
    $basketfullvalue = $form_state->getValue('basketfullmsg');
    $basketemptyvalue = $form_state->getValue('basketemptymsg');
      // Retrieve the configuration
    // Retrieve the configuration.
    $this->config('enquirycart.settings')
        // Set the submitted configuration setting
        // Set the submitted configuration setting.
      ->set('title', $form_state->getValue('title'))
        // You can set multiple configurations at once by making
        // multiple calls to set()
@@ -110,5 +107,4 @@ class EnquiryConfigForm extends ConfigFormBase
    parent::submitForm($form, $form_state);
  }

    
}
Loading