Skip to content

Instantly share code, notes, and snippets.

@alnutile
alnutile / behat.inc.php
Created January 11, 2014 00:57
No name iframe
/**
* Sets an iFrame ID to no_name_iframe if there is no ID. You can then add a Switch to iFrame step after it using the na_name_iframe ID.
*
* @Given /^I the set the iframe located in element with an id of "([^"]*)"$/
*/
public function iSetTheIframeLocatedInElementWithAnIdOf($element_id) {
$check = 1; //@todo need to check using js if exists
if($check <= 0) {
@alnutile
alnutile / behat.inc.php
Created January 11, 2014 01:02
Allow user to submit a form with no submit button
/**
* Some forms do not have a Submit button just pass the ID
*
* @Given /^I submit the form with id "([^"]*)"$/
*/
public function iSubmitTheFormWithId($arg)
{
$node = $this->getMainContext()->getSession()->getPage()->find('css', $arg);
if($node) {
$this->getMainContext()->getSession()->executeScript("jQuery('$arg').submit();");
@alnutile
alnutile / alert.php
Last active July 1, 2016 21:01
Dealing with Alerts
/**
* @hidden
*
* @Then /^I click on the alert window$/
*/
public function iClickOnTheAlertWindow() {
$this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->accept_alert();
}
@alnutile
alnutile / behat.inc.php
Created January 11, 2014 01:20
Switch to popup
/**
* @hidden
*
* @Then /^I switch to popup by clicking "([^"]*)"$/
*/
public function iSwitchToPopupByClicking($arg1) {
$originalWindowName = $this->getMainContext()->getSession()->getWindowName();
$this->setMainWindow();
$this->getMainContext()->getSession()->getPage()->clickLink("$arg1"); //Pressing the withdraw button
@alnutile
alnutile / behat.inc.php
Created January 11, 2014 01:27
Test Height
/**
* See if the element (name|label|id) is greater than the % of the window
*
* @Then /^the element "([^"]*)" should be "([^"]*)" percent or greater than the window$/
*/
public function theElementShouldBePercentOrGreaterThanTheWindow($arg1, $arg2)
{
//@todo
$javascript_check = <<<HEREDOC
if(!jQuery('$arg1').length) { return "FAILED"; }
@AkshayKalose
AkshayKalose / ajax_example.info.yml
Last active November 23, 2022 13:40
Drupal 8 - Ajax Example
name: 'Ajax Example'
description: 'Just an Ajax Example'
core: 8.x
type: module
<?php
/**
* @Then /^I fill in wysiwyg on field "([^"]*)" with "([^"]*)"$/
*/
public function iFillInWysiwygOnFieldWith($arg, $arg2)
{
$this->getSession()->executeScript("CKEDITOR.instances.$arg.setData(\"$arg2\");");
}
@woombo
woombo / hook_inline_entity_form_table_fields_alter.module
Last active February 11, 2016 18:12
hook_inline_entity_form_table_fields_alter()
/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function MODULE_inline_entity_form_table_fields_alter(&$fields, $context) {
if ($context['parent_bundle'] === 'MODULE' &&
$context['entity_type'] === 'MODULE_text_asset') {
// Remove Title.
unset($fields['id']);
@crittermike
crittermike / get_node_by_path.php
Created September 16, 2016 15:15 — forked from thagler/get_node_by_path.php
Drupal 8 Get node ID by path alias
<?php
$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');
if(preg_match('/node\/(\d+)/', $path, $matches)) {
$node = \Drupal\node\Entity\Node::load($matches[1]);
}
@slivorezka
slivorezka / get_image_path_with_image_style.php
Created November 8, 2016 10:40
Drupal 8: Get Image URL / URI with Image Style
<?php
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
// File ID.
$fid = 123;
// Load file.
$file = File::load($fid);
// Get origin image URI.
$image_uri = $file->getFileUri();
// Load image style "thumbnail".