Skip to content

Instantly share code, notes, and snippets.

Avatar
🐎
Steady

Vishwa Chikate vishwac09

🐎
Steady
  • Srijan Technologies Ltd
  • Pune, India
  • Twitter @vishwac09
View GitHub Profile
@vishwac09
vishwac09 / methodAPI.php
Created Sep 22, 2022
EntityConvert methods API
View methodAPI.php
<?php
use DrupalUtils\EntityConvert\EntityConvert;
$entityConvert = new EntityConvert();
// $instance == Node/User/Taxonomy/File.
$entityConvert->toArray($instance, true);
$entityConvert->toObject($instance, false);
// The toArray method accepts 2 arguments.
@vishwac09
vishwac09 / EntityConvert.php
Created Sep 22, 2022
Using the Entity Convert Library
View EntityConvert.php
<?php
use Drupal\node\Entity\Node;
// Include the library.
use DrupalUtils\EntityConvert\EntityConvert;
// Load instance of node
$node = Node::load(1);
@vishwac09
vishwac09 / toArray.php
Last active Sep 22, 2022
EntityConvert getting response as an array
View toArray.php
<?php
use Drupal\Node\Entity\Node;
use DrupalUtils\EntityConvert\EntityConvert;
// Load instance of node
$node = Node::load(1);
// Creating a new Instance.
$entityConvert = new EntityConvert();
@vishwac09
vishwac09 / toObject.php
Last active Sep 22, 2022
EntityConvert getting response as an object
View toObject.php
<?php
use Drupal\Node\Entity\Node;
use DrupalUtils\EntityConvert\EntityConvert;
// Load instance of node
$node = Node::load(1);
// Creating a new Instance.
$entityConvert = new EntityConvert();
@vishwac09
vishwac09 / RestAuth.php
Last active Jun 25, 2022
Drupal8 AuthenticationProvider Example
View RestAuth.php
<?php
namespace Drupal\rest_auth\Authentication;
use Drupal\Core\Authentication\AuthenticationProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Session\UserSession;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
View ChangeBaseFieldType.php
<?php
function vehicle_update_8001() {
$database = \Drupal::database();
$transaction = $database->startTransaction();
$entity_type_manager = \Drupal::entityTypeManager();
// The entity whose field type needs to be updated.
$bundle_of = 'vehicle';
@vishwac09
vishwac09 / Invitation.php
Created Mar 22, 2022
PHP Pseudo code showing resource handler implementation for PATCH requests.
View Invitation.php
<?php
class Invitation {
/**
* Callback handler for HTTP Patch request.
* @param int|null $id
* @param Request|null $request
*/
public function patch(int $id = NULL, Request $request = NULL) {
@vishwac09
vishwac09 / AuthZeroServiceTest.php
Created Mar 18, 2022
AuthZeroServiceTest UnitTest Case implementation
View AuthZeroServiceTest.php
<?php
namespace Drupal\Tests\authzero\Unit;
use Drupal\authzero\Service\AuthZeroService;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
@vishwac09
vishwac09 / AuthZeroService.php
Created Mar 18, 2022
AuthZeroService snippet for writing Unit Test cases
View AuthZeroService.php
<?php
namespace Drupal\authzero\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
/**
* Set of utility functions.
*/
class AuthZeroService {
View ExtendedPHPGuideline.php
<?php
// Violates Import order nto gouped.
use Auth0\SDK\Auth0;
use Drupal\my_custom_module_1\Service\UserService;
use Drupal\my_custom_module_1\Entity\UserEntity;
use Drupal\my_custom_module_2\Service\MessageService;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Field\FieldItemList;