Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Drupal\comment\Plugin\views\field; use Drupal\views\Attribute\ViewsField..

Decoded Output download

<?php

namespace Drupal\comment\Pluginiewsield;

use Drupaliews\Attribute\ViewsField;
use Drupaliews\Pluginiewsield\EntityField;
use Drupaliews\ResultRow;

/**
 * Views field display for commented entity.
 */
#[ViewsField("commented_entity")]
class CommentedEntity extends EntityField {

  /**
   * Array of entities that has comments.
   *
   * We use this to load all the commented entities of same entity type at once
   * to the EntityStorageController static cache.
   *
   * @var array
   */
  protected $loadedCommentedEntities = [];

  /**
   * {@inheritdoc}
   */
  public function getItems(ResultRow $values) {
    if (empty($this->loadedCommentedEntities)) {
      $result = $this->view->result;

      $entity_ids_per_type = [];
      foreach ($result as $value) {
        /** @var \Drupal\comment\CommentInterface $comment */
        if ($comment = $this->getEntity($value)) {
          $entity_ids_per_type[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId();
        }
      }

      foreach ($entity_ids_per_type as $type => $ids) {
        $this->loadedCommentedEntities[$type] = $this->entityTypeManager->getStorage($type)->loadMultiple($ids);
      }
    }

    return parent::getItems($values);
  }

}
 ?>

Did this file decode correctly?

Original Code

<?php

namespace Drupal\comment\Plugin\views\field;

use Drupal\views\Attribute\ViewsField;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\views\ResultRow;

/**
 * Views field display for commented entity.
 */
#[ViewsField("commented_entity")]
class CommentedEntity extends EntityField {

  /**
   * Array of entities that has comments.
   *
   * We use this to load all the commented entities of same entity type at once
   * to the EntityStorageController static cache.
   *
   * @var array
   */
  protected $loadedCommentedEntities = [];

  /**
   * {@inheritdoc}
   */
  public function getItems(ResultRow $values) {
    if (empty($this->loadedCommentedEntities)) {
      $result = $this->view->result;

      $entity_ids_per_type = [];
      foreach ($result as $value) {
        /** @var \Drupal\comment\CommentInterface $comment */
        if ($comment = $this->getEntity($value)) {
          $entity_ids_per_type[$comment->getCommentedEntityTypeId()][] = $comment->getCommentedEntityId();
        }
      }

      foreach ($entity_ids_per_type as $type => $ids) {
        $this->loadedCommentedEntities[$type] = $this->entityTypeManager->getStorage($type)->loadMultiple($ids);
      }
    }

    return parent::getItems($values);
  }

}

Function Calls

None

Variables

None

Stats

MD5 c402d32ec6e31f4de56e83d12f9a9677
Eval Count 0
Decode Time 89 ms