created materio_sapi module and draft of search form block
This commit is contained in:
7
web/modules/custom/materio_sapi/materio_sapi.info.yml
Normal file
7
web/modules/custom/materio_sapi/materio_sapi.info.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
name: Materio Serach API
|
||||
type: module
|
||||
description: 'Search Api Materio module'
|
||||
core: 8.x
|
||||
package: 'Materio'
|
||||
dependencies:
|
||||
- search_api
|
24
web/modules/custom/materio_sapi/materio_sapi.module
Normal file
24
web/modules/custom/materio_sapi/materio_sapi.module
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains materio_sapi.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function materio_sapi_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
// Main module help for the materio_sapi module.
|
||||
case 'help.page.materio_sapi':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('Search Api Materio module') . '</p>';
|
||||
return $output;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
|
||||
access materio search:
|
||||
title: 'Access materio search'
|
||||
description: 'Allow access to materio search'
|
9
web/modules/custom/materio_sapi/materio_sapi.routing.yml
Normal file
9
web/modules/custom/materio_sapi/materio_sapi.routing.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# materio_sapi.materio_sapi_search_form:
|
||||
# path: '/materio_sapi/form/materio_sapi_search'
|
||||
# defaults:
|
||||
# _form: '\Drupal\materio_sapi\Form\MaterioSapiSearchForm'
|
||||
# _title: 'MaterioSapiSearchForm'
|
||||
# requirements:
|
||||
# _access: 'TRUE'
|
||||
#
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\materio_sapi\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class MaterioSapiSearchForm.
|
||||
*/
|
||||
class MaterioSapiSearchForm extends FormBase {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'materio_sapi_search_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['search'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Search'),
|
||||
'#maxlength' => 64,
|
||||
'#size' => 64,
|
||||
'#weight' => '0',
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Submit'),
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {
|
||||
parent::validateForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
// Display result.
|
||||
foreach ($form_state->getValues() as $key => $value) {
|
||||
drupal_set_message($key . ': ' . $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\materio_sapi\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Provides a 'MaterioSapiSearchBlock' block.
|
||||
*
|
||||
* @Block(
|
||||
* id = "materio_sapi_search_block",
|
||||
* admin_label = @Translation("Materio sapi search block"),
|
||||
* )
|
||||
*/
|
||||
class MaterioSapiSearchBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
$build = [];
|
||||
// $build['materio_sapi_search_block']['#markup'] = 'Implement MaterioSapiSearchBlock.';
|
||||
$form = \Drupal::formBuilder()->getForm('Drupal\materio_sapi\Form\MaterioSapiSearchForm');
|
||||
$build['materio_sapi_search_block'] = $form;
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'access materio search');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user