You are here

abstract class ImceItem in IMCE 8

Same name and namespace in other branches
  1. 8.2 src/ImceItem.php \Drupal\imce\ImceItem

Imce Item.

Hierarchy

Expanded class hierarchy of ImceItem

File

src/ImceItem.php, line 8

Namespace

Drupal\imce
View source
abstract class ImceItem {

  /**
   * Item type.
   *
   * @var string
   */
  public $type;

  /**
   * Item name.
   *
   * @var string
   */
  public $name;

  /**
   * Selected status.
   *
   * @var bool
   */
  public $selected;

  /**
   * Item parent.
   *
   * @var \Drupal\imce\ImceFolder
   */
  public $parent;

  /**
   * File manager.
   *
   * @var \Drupal\imce\ImceFM
   */
  protected $fm;

  /**
   * Item path relative to the root.
   *
   * @var string
   */
  protected $path;

  /**
   * Constructs the item.
   *
   * @param string $name
   *   Item name.
   */
  public function __construct($name) {
    $this->name = $name;
  }

  /**
   * Returns the file manager.
   */
  public function fm() {
    return $this->fm;
  }

  /**
   * Sets the file manager.
   */
  public function setFm(ImceFM $fm) {
    $this->fm = $fm;
  }

  /**
   * Returns the item path relative to the root.
   */
  public function getPath() {
    if (isset($this->path)) {
      return $this->path;
    }
    if ($this->parent) {
      $path = $this->parent
        ->getPath();
      if (isset($path)) {
        return Imce::joinPaths($path, $this->name);
      }
    }
  }

  /**
   * Returns the item uri.
   */
  public function getUri() {
    $path = $this
      ->getPath();
    if (isset($path)) {
      return $this
        ->fm()
        ->createUri($path);
    }
  }

  /**
   * Selects the item.
   */
  public function select() {
    $this
      ->fm()
      ->selectItem($this);
  }

  /**
   * Deselects the item.
   */
  public function deselect() {
    $this
      ->fm()
      ->deselectItem($this);
  }

  /**
   * Removes the item from its parent.
   */
  public function remove() {
    if ($this->parent) {
      $this->parent
        ->removeItem($this);
    }
  }

  /**
   * Removes the item from js.
   */
  public function removeFromJs() {
    $this
      ->fm()
      ->removeItemFromJs($this);
  }

  /**
   * Adds the item to js.
   */
  public function addToJs() {
    $this
      ->fm()
      ->addItemToJs($this);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImceItem::$fm protected property File manager.
ImceItem::$name public property Item name.
ImceItem::$parent public property Item parent.
ImceItem::$path protected property Item path relative to the root.
ImceItem::$selected public property Selected status.
ImceItem::$type public property Item type. 2
ImceItem::addToJs public function Adds the item to js.
ImceItem::deselect public function Deselects the item.
ImceItem::fm public function Returns the file manager.
ImceItem::getPath public function Returns the item path relative to the root.
ImceItem::getUri public function Returns the item uri.
ImceItem::remove public function Removes the item from its parent.
ImceItem::removeFromJs public function Removes the item from js.
ImceItem::select public function Selects the item.
ImceItem::setFm public function Sets the file manager.
ImceItem::__construct public function Constructs the item. 1