RegisterFormPopup.php in Login Popup 8
File
src/Plugin/Block/RegisterFormPopup.php
View source
<?php
namespace Drupal\login_popup\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Url;
use Drupal\Core\Link;
class RegisterFormPopup extends BlockBase {
public function build() {
$url = Url::fromRoute('user.register');
$link_options = array(
'attributes' => array(
'class' => array(
'use-ajax',
'register-popup-form',
),
'data-dialog-type' => 'modal',
),
);
$url
->setOptions($link_options);
$link = Link::fromTextAndUrl(t('Register'), $url)
->toString();
$build = [];
if (\Drupal::currentUser()
->isAnonymous()) {
$build['register_popup_block']['#markup'] = '<div class="Register-popup-link">' . $link . '</div>';
}
$build['register_popup_block']['#attached']['library'][] = 'core/drupal.dialog.ajax';
return $build;
}
}