Skip to content

Instantly share code, notes, and snippets.

View cmcintosh's full-sized avatar
💭
Looking For Projects

Chris McIntosh cmcintosh

💭
Looking For Projects
View GitHub Profile
void Update() {
if ( UMAAnimator == null ) {
foreach (Transform t in transform)
{
if (t.name == "UMACharacter") {
UMAAnimator = t.gameObject.GetComponent<Animator> ();
m_Animator = UMAAnimator;
m_Animator.applyRootMotion = false;
}
}

Create a good backup

Put the site in version control

Create a Github copy of the code if it doesn't already exist. Start your first commit with everything exactly the way it is before you start. If the project already has git, do perserve the git history.

Backup the files and database

Name and Date the backup. Do this before you change anything. Just in case.

<?php
class TempleOfDoomAccessHandler {
public function isJones(AccountInterface $account) { }
public function isBadGuy(AccountInterface $account) { }
public function access(AccountINterface $account, Route $route) {
@cmcintosh
cmcintosh / gist:a4af632e8747f4874ad02e3d022ef9ab
Last active November 30, 2019 17:58
TempleOfDoomViewsAccess.php
<?php
/**
* @ingroup views_access_plugins
*
* @ViewsAccess(
* id = "temple_of_doom",
* title = @Translation("Temple of Doom"),
* help = @Translation("No bad guys will enter, only Dr Jones may set foot inside.")
* )
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return Cache::mergeContexts(parent::getCacheContexts(), [
'user.roles',
'url.path',
'group'
]);
}
/**
* Merges max-age values (expressed in seconds), finds the lowest max-age.
*
* Ensures infinite max-age (Cache::PERMANENT) is taken into account.
*
* @param int $a
* Max age value to merge.
* @param int $b
* Max age value to merge.
*
/**
* Sets expires and max-age for bubbled-up max-age values that are > 0.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The response event.
*
* @throws \Exception
* Thrown when \DateTime() cannot create a new date object from the
* arguments passed in.
*/
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Cache this for 1 minute.
return 60;
}
@cmcintosh
cmcintosh / import.php
Created August 6, 2020 13:20 — forked from crittermike/import.php
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
// Assumes $data has the data you want to import for this config.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
@cmcintosh
cmcintosh / D8 | Programmatically Create Field.md
Created October 20, 2020 20:56 — forked from jacerider/D8 | Programmatically Create Field.md
Programmatically create a field in Drupal 8.
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;

$bundles = ['user'];

$fields['user_picture'] = [
  'type' => 'image',
  'entity_type' => 'user',
  'bundle' => 'user',