Add yes/no select with additional checkbox allowing to specify another email

@param string $elementname
@param string $stridentifier
@param array|null $options options for the select element
@param bool $highlight highlight as a new field
439149
protected function add_select_with_email($elementname, $stridentifier, $options = null, $highlight = false) {
        $mform = $this->_form;

        if ($options === null) {
            $options = [0 => get_string('no'), 1 => get_string('yes')];
        }

        $group = [
            $mform->createElement('select', $elementname, get_string($stridentifier, 'hub'), $options),
            $mform->createElement('static', $elementname . 'sep', '', '<br/>'),
            $mform->createElement('advcheckbox', $elementname . 'newemail', '', get_string('usedifferentemail', 'hub'),
                ['onchange' => "this.form.elements['{$elementname}email'].focus();"]),
            $mform->createElement('text', $elementname . 'email', get_string('email'))
        ];

        $element = $mform->addElement('group', $elementname . 'group', get_string($stridentifier, 'hub'), $group, '', false);
        if ($highlight) {
            $element->setAttributes(['class' => $element->getAttribute('class') . ' needsconfirmation mark']);
        }
        $mform->hideIf($elementname . 'email', $elementname, 'eq', 0);
        $mform->hideIf($elementname . 'newemail', $elementname, 'eq', 0);
        $mform->hideIf($elementname . 'email', $elementname . 'newemail', 'notchecked');
        $mform->setType($elementname, PARAM_INT);
        $mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation().
        $mform->addHelpButton($elementname . 'group', $stridentifier, 'hub');

    }
94555
public function createInlineElement($selector, $name = null)
    {
        $elementClass = $this->classNameResolver->resolveElement($name ? $name : 'SensioLabs\Behat\PageObjectExtension\PageObject\InlineElement');

        if ('SensioLabs\Behat\PageObjectExtension\PageObject\InlineElement' !== $elementClass && !is_subclass_of($elementClass, 'SensioLabs\Behat\PageObjectExtension\PageObject\InlineElement')) {
            throw new \InvalidArgumentException(sprintf('Not a page object class: %s', ''));
        }

        return new $elementClass($selector, $this->mink->getSession(), $this);
    }
364090
public static function highlight_string($source, $language, $return = false, $opts = 0)
    {
        if (is_int($return)) {
            $opts = $return;
            $return = false;
        }

        $gs = new static($source, $language, $opts);
        $s = $gs->parseCode();

        if ($gs->error()) {
            return false;
        }

        if ($return) {
            return '<code>' . $s . '</code>';
        }
        echo '<code>' . $s . '</code>';

        return true;
    }
478429
public function setElementInsteadOf($targetName, $element, $name = null) {
		if (! isset($this->_elements[$targetName])) {
			return $this;
		}
		
		$elements = [];
		
		foreach ($this->_elements as $existsName => $existsElement) {
			
			if ($targetName === $existsName) {
				if ($name === null) {
					$elements[] = $element;
				} else {
					$elements[$name] = $element;
				}
			} else {
				$elements[$existsName] = $existsElement;
			}
		}
		
		$this->_elements = $elements;
		
		return $this;
	}
779696
function elementMatches (el, selector) {
  if (el.matches) { return el.matches(selector) }
  if (el.msMatchesSelector) { return el.msMatchesSelector(selector) }
  if (el.webkitMatchesSelector) { return el.webkitMatchesSelector(selector) }
}
699830
public function addElement($elementName, $content, $attributes = null)
    {
        $this->elements[$elementName]['name'] = $elementName;
        $this->elements[$elementName]['content'] = $content;
        $this->elements[$elementName]['attributes'] = $attributes;
    }
617730
function(element, options) {
    this.element = $(element).addClass('colorpicker-element');
    this.options = $.extend(true, {}, defaults, this.element.data(), options);
    this.component = this.options.component;
    this.component = (this.component !== false) ? this.element.find(this.component) : false;
    if (this.component && (this.component.length === 0)) {
      this.component = false;
    }
    this.container = (this.options.container === true) ? this.element : this.options.container;
    this.container = (this.container !== false) ? $(this.container) : false;

    // Is the element an input? Should we search inside for any input?
    this.input = this.element.is('input') ? this.element : (this.options.input ?
      this.element.find(this.options.input) : false);
    if (this.input && (this.input.length === 0)) {
      this.input = false;
    }
    // Set HSB color
    this.color = this.createColor(this.options.color !== false ? this.options.color : this.getValue());

    this.format = this.options.format !== false ? this.options.format : this.color.origFormat;

    if (this.options.color !== false) {
      this.updateInput(this.color);
      this.updateData(this.color);
    }

    this.disabled = false;

    // Setup picker
    var $picker = this.picker = $(this.options.template);
    if (this.options.customClass) {
      $picker.addClass(this.options.customClass);
    }
    if (this.options.inline) {
      $picker.addClass('colorpicker-inline colorpicker-visible');
    } else {
      $picker.addClass('colorpicker-hidden');
    }
    if (this.options.horizontal) {
      $picker.addClass('colorpicker-horizontal');
    }
    if (
      (['rgba', 'hsla', 'alias'].indexOf(this.format) !== -1) ||
      this.options.format === false ||
      this.getValue() === 'transparent'
    ) {
      $picker.addClass('colorpicker-with-alpha');
    }
    if (this.options.align === 'right') {
      $picker.addClass('colorpicker-right');
    }
    if (this.options.inline === true) {
      $picker.addClass('colorpicker-no-arrow');
    }
    if (this.options.colorSelectors) {
      var colorpicker = this,
        selectorsContainer = colorpicker.picker.find('.colorpicker-selectors');

      if (selectorsContainer.length > 0) {
        $.each(this.options.colorSelectors, function(name, color) {
          var $btn = $('<i />')
            .addClass('colorpicker-selectors-color')
            .css('background-color', color)
            .data('class', name).data('alias', name);

          $btn.on('mousedown.colorpicker touchstart.colorpicker', function(event) {
            event.preventDefault();
            colorpicker.setValue(
              colorpicker.format === 'alias' ? $(this).data('alias') : $(this).css('background-color')
            );
          });
          selectorsContainer.append($btn);
        });
        selectorsContainer.show().addClass('colorpicker-visible');
      }
    }

    // Prevent closing the colorpicker when clicking on itself
    $picker.on('mousedown.colorpicker touchstart.colorpicker', $.proxy(function(e) {
      if (e.target === e.currentTarget) {
        e.preventDefault();
      }
    }, this));

    // Bind click/tap events on the sliders
    $picker.find('.colorpicker-saturation, .colorpicker-hue, .colorpicker-alpha')
      .on('mousedown.colorpicker touchstart.colorpicker', $.proxy(this.mousedown, this));

    $picker.appendTo(this.container ? this.container : $('body'));

    // Bind other events
    if (this.input !== false) {
      this.input.on({
        'keyup.colorpicker': $.proxy(this.keyup, this)
      });
      this.input.on({
        'input.colorpicker': $.proxy(this.change, this)
      });
      if (this.component === false) {
        this.element.on({
          'focus.colorpicker': $.proxy(this.show, this)
        });
      }
      if (this.options.inline === false) {
        this.element.on({
          'focusout.colorpicker': $.proxy(this.hide, this)
        });
      }
    }

    if (this.component !== false) {
      this.component.on({
        'click.colorpicker': $.proxy(this.show, this)
      });
    }

    if ((this.input === false) && (this.component === false)) {
      this.element.on({
        'click.colorpicker': $.proxy(this.show, this)
      });
    }

    // for HTML5 input[type='color']
    if ((this.input !== false) && (this.component !== false) && (this.input.attr('type') === 'color')) {

      this.input.on({
        'click.colorpicker': $.proxy(this.show, this),
        'focus.colorpicker': $.proxy(this.show, this)
      });
    }
    this.update();

    $($.proxy(function() {
      this.element.trigger('create');
    }, this));
  }
153873
function(element, options) {
        this.name = name;
        this.$ = $(element);
        this.id = $.zui.uuid();
        this.selectOrder = 1;
        this.selections = {};

        this.getOptions(options);
        this._init();
    }
780805
public function clickFirstVisibleElementOfType($selectorString)
    {
        $page = $this->getSession()->getPage();
        /** @var NodeElement[] $nodes */
        $nodes = $page->findAll('css', $selectorString);
        foreach ($nodes as $node) {
            if ($node->isVisible()) {
                $node->click();
                return;
            }
        }

        throw new ExpectationException(
            "No visible {$selectorString} element found.",
            $this->getSession()->getDriver()
        );
    }
511230
static function laraform($name = '', $options) {
        $gr = new ElementGroupCheckboxButtonTwbs($name);
        $gr->setAttribute('data-toggle', 'buttons');
        foreach ($options as $k => $v) {
            $gr->putCheckboxTwbs($k, $k)
                ->setAttribute('autocomplete', 'off')
                ->setLabel($v);
        }
        return $gr;
    }
770190
protected function createFromSelect($elementName='from', $label='')
    {
        $valid   = array();
        $invalid = array();

        $organization  = $this->mailer->getOrganization();
        // The organization
        $key  = 'organization';
        if ($name = $organization->getContactName()) {
            $extra = $organization->getName();
        } else {
            $name  = $organization->getName();
            $extra = null;
        }
        if ($email = $organization->getEmail()) {
            $title     = false;
            $valid[]   = $key;
        } else {
            $title     = $this->_('Organization does not have an e-mail address.');
            $invalid[] = $key;
        }
        $options[$key] = $this->createMultiOption(array(\MUtil_Model::REQUEST_ID => $organization->getId()),
            $name, $email, $extra, $title,
            array('controller' => 'organization', 'action' => 'edit'));
        $this->fromOptions[$key] = $email;//$name . ' <' . $email . '>';

        // The user
        $key = 'user';
        $name  = $this->currentUser->getFullName();
        $extra = null;
        if ($email = $this->currentUser->getEmailAddress()) {
            $title     = false;
            $valid[]   = $key;
        } else {
            $title     = $this->_('You do not have an e-mail address.');
            $invalid[] = $key;
        }
        $options[$key] = $this->createMultiOption(array(),
            $name, $email, $extra, $title,
            array('controller' => 'option', 'action' => 'edit'));
        $this->fromOptions[$key] = $email;//$name . ' <' . $email . '>';

        // As "the" application
        $key = 'application';
        $user = $this->loader->getCurrentUser();
        if ($user->hasPrivilege('pr.plan.mail-as-application') &&
            isset($this->project->email['site'])) {

            if ($email = $this->project->email['site']) {
                $options['application'] = $this->createMultiOption(array(), $this->project->name, $email);
                $valid[]     = 'application';
                $this->fromOptions[$key] = $email;//$this->project->name . ' <' . $email . '>';
            }
        }

        $firstSelectable = reset($valid);
        $element = $this->form->createElement('radio', $elementName, array(
            'disable'      => $invalid,
            'escape'       => (!$this->view),
            'label'        => $label,
            'multiOptions' => $options,
            'required'     => true,
            'value'        => $firstSelectable,
            ));

        $element->addValidator('InArray', false, array('haystack' => $valid));
        return $element;
    }
823341
public static ElementSelector selectorForElementNamed(final String expectedName,
                                                          final ElementSelector es) {
        if (expectedName == null) {
            throw new IllegalArgumentException("expectedName must not be null");
        }

        return conditionalSelector(elementNamePredicate(expectedName), es);
    }
1097607
public function appendSelector(FileSelector $selector)
    {
        if ($this->isReference()) {
            throw $this->noChildrenAllowed();
        }
        $this->selectorsList[] = $selector;
    }
251513
public function unselectOption($select, $option)
    {
        $el = $this->findField($select);

        $wdSelect = new WebDriverSelect($el);

        if (!is_array($option)) {
            $option = [$option];
        }

        $matched = false;

        foreach ($option as $opt) {
            try {
                $wdSelect->deselectByVisibleText($opt);
                $matched = true;
            } catch (NoSuchElementException $e) {
                // exception treated at the end
            }

            try {
                $wdSelect->deselectByValue($opt);
                $matched = true;
            } catch (NoSuchElementException $e) {
                // exception treated at the end
            }
        }

        if ($matched) {
            return;
        }
        throw new ElementNotFound(json_encode($option), "Option inside $select matched by name or value");
    }
930080
protected function writePaymentSlipLines($elementName, array $element)
    {
        if (!is_string($elementName)) {
            throw new \InvalidArgumentException('$elementName is not a string!');
        }
        if (!isset($element['lines'])) {
            throw new \InvalidArgumentException('$element contains not "lines" key!');
        }
        if (!isset($element['attributes'])) {
            throw new \InvalidArgumentException('$element contains not "attributes" key!');
        }
        $lines = $element['lines'];
        $attributes = $element['attributes'];

        if (!is_array($lines)) {
            throw new \InvalidArgumentException('$lines is not an array!');
        }
        if (!is_array($attributes)) {
            throw new \InvalidArgumentException('$attributes is not an array!');
        }

        $posX = $attributes['PosX'];
        $posY = $attributes['PosY'];
        $height = $attributes['Height'];
        $width = $attributes['Width'];
        $fontFamily = $attributes['FontFamily'];
        $background = $attributes['Background'];
        $fontSize = $attributes['FontSize'];
        $fontColor = $attributes['FontColor'];
        $lineHeight = $attributes['LineHeight'];
        $textAlign = $attributes['TextAlign'];

        $this->setFont($fontFamily, $fontSize, $fontColor);
        if ($background != 'transparent') {
            $this->setBackground($background);
            $fill = true;
        } else {
            $fill = false;
        }

        foreach ($lines as $lineNr => $line) {
            $this->setPosition(
                $this->paymentSlip->getSlipPosX() + $posX,
                $this->paymentSlip->getSlipPosY() + $posY + ($lineNr * $lineHeight)
            );
            $this->createCell($width, $height, $line, $textAlign, $fill);
        }

        return $this;
    }
1186642
protected function defineElement($element, $name = null, $description = null, array $values = [], array $options = [], array $params = [])
    {
        return [
            'name' => $name ?: $element,
            'description' => $description,
            'element' => $element,
            'values' => $values,
            'params' => $params,
        ];
    }
771344
private function selectComponentValue(DocumentElement $page, $component, $field, $value)
    {
        $select = $page->find('css', sprintf('#%s', $field));
        if (!$select) {
            throw new \Exception(sprintf('No select "%s" found', $field));
        }

        $selector = sprintf('.fs-%1$s button.fs-%1$s-item', $component);
        $choices  = $page->findAll('css', $selector);
        foreach ($choices as $choice) {
            if ($choice->getText() == $value) {
                $choice->click();
                return;
            }
        }

        throw new \Exception(sprintf('Value "%s" not found for "%s"', $value, $field));
    }