You are here

protected function BynderSearch::checkType in Bynder 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::checkType()

Check that media type is properly configured.

Return value

bool Returns TRUE if media type is configured correctly.

Overrides BynderWidgetBase::checkType

1 call to BynderSearch::checkType()
BynderSearch::prepareEntities in src/Plugin/EntityBrowser/Widget/BynderSearch.php

File

src/Plugin/EntityBrowser/Widget/BynderSearch.php, line 236

Class

BynderSearch
Uses a Bynder API to search and provide entity listing in a browser's widget.

Namespace

Drupal\bynder\Plugin\EntityBrowser\Widget

Code

protected function checkType() {
  if (parent::checkType()) {
    return TRUE;
  }
  if ($this->configuration['media_type_document']) {

    /** @var \Drupal\media\MediaTypeInterface $type */
    $type = $this->entityTypeManager
      ->getStorage('media_type')
      ->load($this->configuration['media_type_document']);
    if (!$type) {
      (new BundleNotExistException($this->configuration['media_type_document']))
        ->logException()
        ->displayMessage();
      return FALSE;
    }
    elseif (!$type
      ->getSource() instanceof Bynder) {
      (new BundleNotBynderException($type
        ->label()))
        ->logException()
        ->displayMessage();
      return FALSE;
    }
    return TRUE;
  }
  if ($this->configuration['media_type_video']) {

    /** @var \Drupal\media\MediaTypeInterface $type */
    $type = $this->entityTypeManager
      ->getStorage('media_type')
      ->load($this->configuration['media_type_video']);
    if (!$type) {
      (new BundleNotExistException($this->configuration['media_type_video']))
        ->logException()
        ->displayMessage();
      return FALSE;
    }
    elseif (!$type
      ->getSource() instanceof Bynder) {
      (new BundleNotBynderException($type
        ->label()))
        ->logException()
        ->displayMessage();
      return FALSE;
    }
    return TRUE;
  }
  return FALSE;
}