You are here

public function ViewsMegarowLinkEdit::render in Views Megarow 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides EntityLink::render

File

src/Plugin/views/field/ViewsMegarowLinkEdit.php, line 61

Class

ViewsMegarowLinkEdit
Field handler to present a link node edit.

Namespace

Drupal\views_megarow\Plugin\views\field

Code

public function render(ResultRow $values) {
  $entity_type = $values->_entity
    ->getEntityType()
    ->id();
  $id = $values->_entity
    ->id();
  $options = [
    'attributes' => [
      'class' => [
        'use-ajax',
      ],
      'data-dialog-type' => 'modal',
      'data-dialog-options' => Json::encode([
        'width' => 600,
      ]),
    ],
  ];
  $content = [];
  $content['vm_modal_edition'] = [
    '#type' => 'link',
    '#title' => t('Edit'),
    '#url' => Url::fromRoute('views_megarow.edit', [
      'entity_type' => $entity_type,
      'entity' => $id,
      'js' => 'nojs',
    ]),
    '#options' => $options,
    '#attached' => [
      'library' => [
        'core/drupal.dialog.ajax',
      ],
    ],
  ];

  //$content['l']['#markup'] = \Drupal::l('coucou', new Url('entity.node.canonical', ['node' => 1], array('attributes' => array('class' => array('test-refresh')))));

  //    $content['l']['#attached']['library'][] = 'views_megarow/link';
  return $content;
}