You are here

class ViewsMegarowEditController in Views Megarow 8

Hierarchy

Expanded class hierarchy of ViewsMegarowEditController

File

src/Controller/ViewsMegarowEditController.php, line 11

Namespace

Drupal\views_megarow\Controller
View source
class ViewsMegarowEditController {
  public function form() {

    // Extra arguments are in $_REQUEST.
    $request = Drupal::service('request_stack');
    $current_request = $request
      ->getCurrentRequest();
    $entity_type = $current_request
      ->get('entity_type');
    $entity = $current_request
      ->get('entity');
    $operation = 'edit';
    $build = [];
    $form = \Drupal::service('entity.manager')
      ->getFormObject($entity_type, $operation)
      ->setEntity($entity);
    $build[] = \Drupal::formBuilder()
      ->getForm($form);
    return $build;
  }
  public function jsonCallback() {

    //$form = $this->form();
    $renderer = \Drupal::service('renderer');
    $output = $renderer
      ->renderRoot($form);
    $title = $form_state
      ->get('title') ?: '';
    $response = new AjaxResponse();
    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $response
      ->setAttachments($form['#attached']);
    $display = '';
    $status_messages = array(
      '#type' => 'status_messages',
    );
    if ($messages = $renderer
      ->renderRoot($status_messages)) {
      $display = '<div class="views-messages">' . $messages . '</div>';
    }
    $display .= $output;
    $options = array(
      /*'dialogClass' => 'views-ui-dialog js-views-ui-dialog',*/
      'width' => '75%',
    );
    $response
      ->addCommand(new OpenModalDialogCommand($title, $display, $options));
    return $response;
  }
  public function access(AccountInterface $account) {

    // Find a way to call the access handler of the entity for the edit action.
    return AccessResult::allowedIf($account
      ->hasPermission('access content'));
  }

}

Members