Skip to content

Instantly share code, notes, and snippets.

View vishwac09's full-sized avatar
🐢
Steady

Vishwa Chikate vishwac09

🐢
Steady
  • Srijan Technologies Ltd
  • Pune, India
  • X @vishwac09
View GitHub Profile
@vishwac09
vishwac09 / methodAPI.php
Created September 22, 2022 18:15
EntityConvert methods API
<?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 September 22, 2022 17:59
Using the Entity Convert Library
<?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 September 22, 2022 17:57
EntityConvert getting response as an array
<?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 September 22, 2022 17:58
EntityConvert getting response as an object
<?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 June 25, 2022 10:59
Drupal8 AuthenticationProvider Example
<?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;
/**
@vishwac09
vishwac09 / ChangeBaseFieldType.php
Created May 7, 2022 16:25
ChangeBaseFieldType
<?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 March 22, 2022 11:10
PHP Pseudo code showing resource handler implementation for PATCH requests.
<?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 March 18, 2022 16:48
AuthZeroServiceTest UnitTest Case implementation
<?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 March 18, 2022 11:50
AuthZeroService snippet for writing Unit Test cases
<?php
namespace Drupal\authzero\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
/**
* Set of utility functions.
*/
class AuthZeroService {
@vishwac09
vishwac09 / ExtendedPHPGuideline.php
Created March 3, 2022 15:46
ExtendedPHPGuideline
<?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;