You are here

class CloudBlockBase in Gutenberg 8.2

Same name and namespace in other branches
  1. 8 modules/gutenberg_cloud/src/CloudBlockBase.php \Drupal\gutenberg_cloud\CloudBlockBase

Class CloudBlockBase.

Hierarchy

Expanded class hierarchy of CloudBlockBase

File

modules/gutenberg_cloud/src/CloudBlockBase.php, line 8

Namespace

Drupal\gutenberg_cloud
View source
class CloudBlockBase implements CloudBlockInterface {

  /**
   * Block machine name.
   *
   * @var string
   */
  protected $name;

  /**
   * Block version.
   *
   * @var string
   */
  protected $version;

  /**
   * Block label (human readable name).
   *
   * @var string
   */
  protected $label = '';

  /**
   * Block description.
   *
   * @var string
   */
  protected $description = '';

  /**
   * Block screenshot.
   *
   * @var null
   */
  protected $screenshot = NULL;

  /**
   * Block js.
   *
   * @var null
   */
  protected $js = NULL;

  /**
   * Block edit css.
   *
   * @var null
   */
  protected $edit_css = NULL;

  /**
   * Block view css.
   *
   * @var null
   */
  protected $view_css = NULL;

  /**
   * CloudBlockBase constructor.
   *
   * @param array $block
   *   Cloud block structure.
   */
  public function __construct(array $block) {
    $this
      ->setConfig($block);
  }

  /**
   * Getter for name.
   */
  public function getName() {
    return $this->name;
  }

  /**
   * Getter for version.
   */
  public function getVersion() {
    return $this->version;
  }

  /**
   * Getter for label.
   */
  public function getLabel() {
    return $this->label;
  }

  /**
   * Getter for description.
   */
  public function getDescription() {
    return $this->description;
  }

  /**
   * Getter for screenshot.
   */
  public function getScreenshot() {
    return $this->screenshot;
  }

  /**
   * Getter for js.
   */
  public function getJs() {
    return $this->js;
  }

  /**
   * Getter for edit css.
   */
  public function getEditCss() {
    return $this->edit_css;
  }

  /**
   * Getter for view css.
   */
  public function getViewCss() {
    return $this->view_css;
  }

  /**
   * Getter for object properties.
   *
   * @param string $property
   *   Property name.
   *
   * @return mixed|null
   *   Properety value or NULL if property doesn't exists.
   */
  public function get(string $property) {
    return $this
      ->getConfig()[$property] ?? NULL;
  }

  /**
   * Getter for properties related to Cloud Block config.
   *
   * @return array
   *   Array of properties.
   */
  public function getConfig() {
    return [
      'name' => $this->name,
      'version' => $this->version,
      'label' => $this->label,
      'description' => $this->description,
      'screenshot' => $this->screenshot,
      'js' => $this->js,
      'edit_css' => $this->edit_css,
      'view_css' => $this->view_css,
    ];
  }

  /**
   * Sets object properties based on a given array.
   *
   * @param array $config
   *   Associative array.
   */
  protected function setConfig(array $config) {
    foreach ($config as $property => $value) {
      if (property_exists($this, $property)) {
        $this->{$property} = $value;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CloudBlockBase::$description protected property Block description.
CloudBlockBase::$edit_css protected property Block edit css.
CloudBlockBase::$js protected property Block js.
CloudBlockBase::$label protected property Block label (human readable name).
CloudBlockBase::$name protected property Block machine name.
CloudBlockBase::$screenshot protected property Block screenshot.
CloudBlockBase::$version protected property Block version.
CloudBlockBase::$view_css protected property Block view css.
CloudBlockBase::get public function Getter for object properties. Overrides CloudBlockInterface::get
CloudBlockBase::getConfig public function Getter for properties related to Cloud Block config. Overrides CloudBlockInterface::getConfig
CloudBlockBase::getDescription public function Getter for description. Overrides CloudBlockInterface::getDescription
CloudBlockBase::getEditCss public function Getter for edit css. Overrides CloudBlockInterface::getEditCss
CloudBlockBase::getJs public function Getter for js. Overrides CloudBlockInterface::getJs
CloudBlockBase::getLabel public function Getter for label. Overrides CloudBlockInterface::getLabel
CloudBlockBase::getName public function Getter for name. Overrides CloudBlockInterface::getName
CloudBlockBase::getScreenshot public function Getter for screenshot. Overrides CloudBlockInterface::getScreenshot
CloudBlockBase::getVersion public function Getter for version. Overrides CloudBlockInterface::getVersion
CloudBlockBase::getViewCss public function Getter for view css. Overrides CloudBlockInterface::getViewCss
CloudBlockBase::setConfig protected function Sets object properties based on a given array.
CloudBlockBase::__construct public function CloudBlockBase constructor. 1