customers_canvas-8.x-1.0-rc4/src/Controller/Builder.php

src/Controller/Builder.php
<?php

namespace Drupal\customers_canvas\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Defines HelloController class.
 */
class Builder extends ControllerBase {

  /**
   * Display the builder for a particular user and entity.
   *
   * @param \Drupal\Core\Session\AccountInterface $user
   *   The creation belongs to a user, usually the current but not always.
   * @param \Drupal\Core\Entity\EntityInterface $cc_entity
   *   The entity that stores the JSON builder string specific to the Customers
   *   Canvas implementation.
   *
   * @return array
   *   Return markup array.
   */
  public function content(AccountInterface $user, EntityInterface $cc_entity) {
    $product_json = $cc_entity->get('cc_product_json');
    if ($product_json) {
      $product_json = $product_json->getValue()[0]['value'];
      $builder_json = $this->config('customers_canvas.settings')->get('builder_json');

      // Inject settings for user id.
      // See https://customerscanvas.com/docs/cc/customerscanvas.iframeapi.configuration.iconfiguration.htm
      $builder_json = json_decode($builder_json, TRUE);
      $builder_json['userId'] = $user->id();
      $builder_json = json_encode($builder_json);

      return [
        '#theme' => 'customers_canvas_builder',
        '#owner' => $user,
        '#entity' => $cc_entity,
        '#finish_form' => $this->formBuilder()->getForm('Drupal\customers_canvas\Form\Builder', [
          'cc_entity' => $cc_entity,
          'owner' => $user,
        ]),
        '#attached' => [
          'library' => ['customers_canvas/builder'],
          'drupalSettings' => [
            'customersCanvas' => [
              'productJson' => $product_json,
              'builderJson' => $builder_json,
            ],
          ],
        ],
      ];
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc