ViewsMegarowEditController.php in Views Megarow 8
Namespace
Drupal\views_megarow\ControllerFile
src/Controller/ViewsMegarowEditController.phpView source
<?php
namespace Drupal\views_megarow\Controller;
use Drupal;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Ajax\OpenModalDialogCommand;
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'));
}
}
Classes
Name | Description |
---|---|
ViewsMegarowEditController |