This file contains 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 InvalidArgumentException; | |
/** | |
* Rotate an image DataURI string. | |
* | |
* Because I'm working with a string, not a file, the Drupal image API | |
* (image.factory) didn't seem to be an appropriate solution, therefor I'm using | |
* the native PHP GD library. | |
*/ |
This file contains 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; |
This file contains 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 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 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 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 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 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 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 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); |
NewerOlder