You are here

public static function BlockUploadManager::blockUploadBuildBlockContent in Block Upload 8

Builds contents of block upload by its id.

Parameters

int $block_id: Block upload variable ID.

Return value

array Block with content.

1 call to BlockUploadManager::blockUploadBuildBlockContent()
BlockUploadBlock::build in src/Plugin/Block/BlockUploadBlock.php
Build the content for mymodule block.

File

src/BlockUploadManager.php, line 25

Class

BlockUploadManager
BlockUploadManager class.

Namespace

Drupal\block_upload

Code

public static function blockUploadBuildBlockContent($block_id) {
  $block = [];
  if (\Drupal::request()->attributes
    ->has('node')) {
    $node = \Drupal::request()->attributes
      ->get('node');
  }
  $field_name = \Drupal::state()
    ->get('block_upload_' . $block_id . '_field') ?: '';
  $field = FieldStorageConfig::loadByName(explode('.', $field_name)[0], explode('.', $field_name)[1]);
  if (isset($field) && !empty($field
    ->getBundles())) {
    foreach ($field
      ->getBundles() as $bundle) {
      if (isset($node)) {
        if ($bundle == $node
          ->getType()) {
          $settings = \Drupal::state()
            ->get('block_upload_' . $block_id . '_settings' ?: []);

          // Simple file upload form.
          if ($settings['plupload']) {
            $block = \Drupal::formBuilder()
              ->getForm('Drupal\\block_upload\\Form\\BlockUploadPluploadForm', $node, $block_id);
          }
          else {
            $block = \Drupal::formBuilder()
              ->getForm('Drupal\\block_upload\\Form\\BlockUploadForm', $node, $block_id);
          }
        }
      }
    }
  }
  return $block;
}