This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Throw an exception for a bash file, message and exit code. | |
* | |
* This class creates an exception where getFile returns a path with the correct | |
* basename, and in some cases the correct line number where the exit code | |
* occurred. | |
*/ | |
class ThrowShellError { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$version = class_exists('\Drupal') ? Drupal::VERSION : NULL; | |
$version = $version ?? (defined('VERSION') ? constant('VERSION') : NULL); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\se_core\Helpers; | |
use DateTimeInterface; | |
use DateTimeZone; | |
use Drupal\Core\Entity\Query\QueryInterface; | |
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; | |
use Drupal\field\Entity\FieldStorageConfig; | |
use RuntimeException; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\se_core\Plugin\Field\FieldWidget; | |
use Drupal; | |
use Drupal\Component\Utility\Color; | |
use Drupal\Core\Field\FieldItemListInterface; | |
use Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget; | |
use Drupal\Core\Field\WidgetBase; | |
use Drupal\Core\Form\FormStateInterface; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\se_core\Plugin\Field\FieldWidget; | |
use Drupal; | |
use Drupal\Component\Utility\Color; | |
use Drupal\Component\Utility\NestedArray; | |
use Drupal\Core\Field\FieldItemListInterface; | |
use Drupal\Core\Field\WidgetBase; | |
use Drupal\Core\Form\FormStateInterface; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\se_core\Traits; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Entity\Entity\EntityFormDisplay; | |
trait GetFormModeTrait { | |
protected function getFormMode(FormStateInterface $form_state): string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\paragraphs\ParagraphInterface; | |
/** | |
* Get the delta on the host entity for a paragraph. | |
*/ | |
class GetHostDelta { | |
public function __invoke(ParagraphInterface $paragraph): ?string { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FormatPhoneNumber { | |
const FORMAT = '(%d) %d-%d'; | |
const SMS_FORMAT = '+1%d%d%d'; | |
public function __invoke(string $number, string $format = NULL) { | |
$number = preg_replace('#[^0-9]#', '', $number); | |
preg_match('#(.+)?(\d{3})(\d{3})(\d{4})$#', $number, $matches); | |
array_shift($matches); | |
array_shift($matches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countPalindromes($word) { | |
$palindromes = 0; | |
$word_length = strlen($word); | |
for ($chunk_size = $word_length; $chunk_size > 0; --$chunk_size) { | |
for ($pos = 0; $pos <= ($word_length - $chunk_size); $pos++) { | |
$substr = substr($word, $pos, $chunk_size); | |
if ($substr === strrev($substr)) { | |
++$palindromes; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$augmented_message = $exception->getMessage() . "\nMy augementation"; | |
$reflected_exception = new \ReflectionObject($exception); | |
$message_property = $reflected_exception->getProperty('message'); | |
$message_property->setAccessible(TRUE); | |
$message_property->setValue($exception, $augmented_message); | |
throw $exception; |