Skip to content

Instantly share code, notes, and snippets.

View undertext's full-sized avatar

Yaroslav Kharchenko undertext

View GitHub Profile
<?php
/**
* Implements hook_stream_wrappers.
*/
function fics_stream_wrapper_stream_wrappers() {
return array(
'fics' => array(
'name' => t('FICS'),
'class' => 'FICSStreamWrapper',

Keybase proof

I hereby claim:

  • I am undertext on github.
  • I am undertext (https://keybase.io/undertext) on keybase.
  • I have a public key ASDErUHwIcOFnw_z6oKVZF7F9TDuHg-CFujOnf_KU6LxAwo

To claim this, I am signing this object:

@undertext
undertext / docker-compose.yml
Last active April 2, 2019 11:25
Drupal docker-compose
version: "3"
services:
mariadb:
container_name: "drupal_testing_mariadb"
image: wodby/mariadb
container_name: "mariadb"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: drupal
@undertext
undertext / UrbanDictionaryService.php
Last active May 8, 2019 09:24
UrbanDictionaryService class
public function getDefinition($term) {
try {
$response = $this->httpClient->request('GET', "http://urbanscraper.herokuapp.com/define/$term");
} catch (GuzzleException $e) {
$this->logger->error($e->getMessage());
return NULL;
}
$json = json_decode($response->getBody());
return new UrbanDefinition($json->term, $json->definition, $json->example);
}
<?php
namespace Drupal\tests\urban_module\Unit;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\urban_module\Service\UrbanDictionaryService;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\RequestInterface;
<testsuites>
<testsuite name="unit">
<file>./tests/TestSuites/UnitTestSuite.php</file>
</testsuite>
<testsuite name="kernel">
<file>./tests/TestSuites/KernelTestSuite.php</file>
</testsuite>
<testsuite name="functional">
<file>./tests/TestSuites/FunctionalTestSuite.php</file>
</testsuite>
<?php
function urban_module_node_presave(NodeInterface $node) {
if ($node->bundle() == 'urban_definition') {
/** @var \Drupal\urban_module\Service\UrbanDictionaryService $ubService */
$ubService = \Drupal::service('urban_module.service');
$definition = $ubService->getDefinition($node->getTitle());
if (!empty($definition)) {
$node->title->value = $definition->getTerm();
$node->field_definition->value = $definition->getDefinition();
<?php
namespace Drupal\tests\urban_module\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
<?php
namespace Drupal\urban_module\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
<?php
namespace Drupal\tests\urban_module\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests urban definition list block.
*/
class UrbanDefinitionListBlockTest extends BrowserTestBase {