outline-8.x-1.x-dev/modules/outline_graphql/src/Plugin/GraphQL/DataProducer/Entry/Mutation/Expand.php

modules/outline_graphql/src/Plugin/GraphQL/DataProducer/Entry/Mutation/Expand.php
<?php

namespace Drupal\outline_graphql\Plugin\GraphQL\DataProducer\Entry\Mutation;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * @DataProducer(
 *   id = "expand_entry",
 *   name = @Translation("Expand Entry"),
 *   description = @Translation("Expands the entry."),
 *   produces = @ContextDefinition("boolean",
 *     label = @Translation("Success")
 *   ),
 *   consumes = {
 *     "eid" = @ContextDefinition("integer",
 *       label = @Translation("Entry ID"),
 *       required = TRUE
 *     ),
 *     "depth" = @ContextDefinition("integer",
 *       label = @Translation("Expansion Depth"),
 *       required = FALSE
 *     ),
 *   }
 * )
 */
class Expand extends DataProducerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('current_user')
    );
  }

  /**
   * Expand Entry constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   */
  public function __construct(array $configuration, string $plugin_id, array $plugin_definition, AccountInterface $current_user) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->currentUser = $current_user;
  }

  /**
   * Expands the entry.
   *
   * @param integer $eid
   *   The entry to expand.
   * @param integer $depth
   *   The number of levels deep to expand.
   *
   * @return bool
   *   Success.
   *
   * @throws \Exception
   */
  public function resolve(int $eid, int $depth = 0) {

    //if ($this->currentUser->hasPermission("change parent entry")) {

    /* @var $entry \Drupal\outline\EntryInterface */

    // Get the entry.
    $entry = \Drupal::entityTypeManager()
      ->getStorage('outline_entry')
      ->load($eid);

    // Update Expanded
    $entry->setExpanded(TRUE, $depth);
    $entry->save();
    $entry->saveChildren();

    // Return.
    return TRUE;

    //}
    //return NULL;

  }

}

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

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