Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. module
  2. ------custom
  3. ------------onyx_experiencia
  4. ----------------------------onyx_experiencia.info.yml
  5. ----------------------------onyx_experiencia.libraries.yml
  6. ----------------------------onyx_experiencia.module
  7. ----------------------------css
  8. -------------------------------onyx_serv_css.css
  9. ----------------------------templates
  10. -------------------------------------onyx-experiencia.html.twig
  11. ----------------------------src
  12. -------------------------------Plugin
  13. -------------------------------------Block
  14. ------------------------------------------onyx_experiencia.php
  15.  
  16. name: Onyx Servicios
  17. description: Block de Servicios de OnyxGroup
  18. core: 8.x
  19. package: Custom
  20. dependencies:
  21. - block
  22. type: module
  23.  
  24. onyx-experiencia-style:
  25. version: 1.x
  26. css:
  27. theme:
  28. css/onyx_serv_css.css: {}
  29.  
  30. <?php
  31. /**
  32. * Implements hook_theme().
  33. */
  34. function onyx_experiencia_theme() {
  35. return [
  36. 'onyx-experiencia' => [
  37. 'variables' => [
  38. 'CardTitle' => NULL,
  39. ],
  40. ],
  41. ];
  42. }
  43.  
  44. <?php
  45.  
  46. namespace Drupalonyx_experienciaPluginBlock;
  47.  
  48.  
  49.  
  50. use DrupalCoreBlockBlockBase;
  51. use DrupalCoreBlockBlockPluginInterface;
  52. use DrupalCoreFormFormStateInterface;
  53. use DrupalfileEntityFile;
  54. use DruapimageEntityImageStyle;
  55.  
  56.  
  57.  
  58. /**
  59. * Provides a 'Onyx' Block.
  60. *
  61. * @Block(
  62. * id = "onyx_experiencia",
  63. * admin_label = @Translation("Servicios OnyxGroup"),
  64. * category = @Translation("Servicios OnyxGroup"),
  65. * )
  66. */
  67. class onyx_experiencia extends BlockBase implements BlockPluginInterface {
  68.  
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function build() {
  73. $config = $this->getConfiguration();
  74. $build = array();
  75.  
  76. if (!empty($config['card_title'])) {
  77. $name = $config['card_title'];
  78. }
  79. else {
  80. $name = $this->t('Onyx Group Card');
  81. }
  82.  
  83. if (!empty($config['card_text'])) {
  84. $cardText = $config['card_text'];
  85. }
  86. else {
  87. $cardText = $this->t('A service of Onyx Group');
  88. }
  89.  
  90. //$build[]['#attached']['library'][] = 'onyx_experiencia/onyx_serv_css';
  91. $build = array(
  92. '#theme' => 'onyx-experiencia',
  93. );
  94.  
  95. $build['CardTitle'] = array(
  96. '#prefix' => '',
  97. '#markup' => $name,
  98. '#suffix' => '',
  99. );
  100.  
  101. $build['CardText'] = array(
  102. '#prefix' => '',
  103. '#markup' => $cardText,
  104. '#suffix' => '',
  105. );
  106.  
  107. $cardImage = $this->configuration['card_image'];
  108. if (!empty($cardImage[0])) {
  109. if ($file = File::load($cardImage[0])) {
  110. $build['CardImg'] = array(
  111. '#theme' => 'image_style',
  112. '#style_name' => 'medium',
  113. '#uri' => $file->getFileUri(),
  114. );
  115. }
  116. }
  117.  
  118. $cardLink = $this->configuration['card_link'];
  119. $build['CardLink'] = array(
  120. '#markup' => $cardLink,
  121. );
  122.  
  123. return $build;
  124.  
  125. }
  126.  
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function blockForm($form, FormStateInterface $form_state) {
  131. $form = parent::blockForm($form, $form_state);
  132.  
  133. $config = $this->getConfiguration();
  134.  
  135. $form['card_title'] = [
  136. '#type' => 'textfield',
  137. '#title' => $this->t('Card Title'),
  138. '#description' => $this->t('Type title of the service card.'),
  139. '#default_value' => isset($config['card_title']) ? $config['card_title'] : '',
  140. ];
  141.  
  142. $form['card_text'] = [
  143. '#type' => 'textarea',
  144. '#title' => $this->t('Card Text'),
  145. '#format' => 'full_html',
  146. '#description' => $this->t('Type the list of the services.'),
  147. '#default_value' => isset($config['card_text']) ? $config['card_text'] : '',
  148. ];
  149.  
  150. $form['card_image'] = [
  151. '#type' => 'managed_file',
  152. '#title' => t('Card image background'),
  153. '#upload_validators' => array(
  154. 'file_validate_extensions' => array('gif png jpg jpeg'),
  155. 'file_validate_size' => array(25600000),
  156. ),
  157. '#theme' => 'image_widget',
  158. '#preview_imgage_style' => 'medium',
  159. '#upload_location' => 'private://card_service_img',
  160. '#progress_message' => 'One moment while we save your file...',
  161. '#default_value' => isset($this->configuration['card_image']) ? $this->configuration['card_image'] : '',
  162. '#required' => TRUE,
  163. ];
  164.  
  165. $form['card_link'] = [
  166. '#title' => t('Type card link. Example: /erp_cloud'),
  167. '#type' => 'url',
  168. '#default_value' => isset($this->configuration['card_link']) ? $this->configuration['card_link'] : '',
  169.  
  170. ];
  171.  
  172. return $form;
  173. }
  174.  
  175. /**
  176. * Custom submit actions
  177. */
  178. public function custom_submit_form($form, FormStateInterface $form_state) {
  179. $values = $form_state->getValues();
  180. //Perform the required actions
  181. }
  182.  
  183. /**
  184. * {@inheritdoc}
  185. */
  186. public function blockSubmit($form, FormStateInterface $form_state) {
  187.  
  188. $cardImage = $form_state->getValue('card_image');
  189. if ($cardImage != $this->configuration['card_image']) {
  190. if (!empty($cardImage[0])) {
  191. $file = File::load($cardImage[0]);
  192. $file->setPermanent();
  193. $file->save;
  194. }
  195. }
  196.  
  197. $this->configuration['card_title'] = $form_state->getValue('card_title');
  198. $this->configuration['card_text'] = $form_state->getValue('card_text');
  199. $this->configuration['card_image'] = $form_state->getValue('card_image');
  200. $this->configuration['card_link'] = $form_state->getValue('card_link');
  201. }
  202.  
  203. }
  204.  
  205. {#
  206. /**
  207. * @file
  208. * Profile for onyx_experiencia block.
  209. */
  210. #}
  211. {{ attach_library('onyx_experiencia/onyx_serv_css')}}
  212.  
  213. <div class="cardTitle">
  214. {{form.CardTitle}}
  215. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement